Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 597d795

Browse files
kiryltorvalds
authored andcommitted
mm: do not allocate page->ptl dynamically, if spinlock_t fits to long
In struct page we have enough space to fit long-size page->ptl there, but we use dynamically-allocated page->ptl if size(spinlock_t) is larger than sizeof(int). It hurts 64-bit architectures with CONFIG_GENERIC_LOCKBREAK, where sizeof(spinlock_t) == 8, but it easily fits into struct page. Signed-off-by: Kirill A. Shutemov <[email protected]> Acked-by: Hugh Dickins <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent fff4068 commit 597d795

File tree

5 files changed

+8
-7
lines changed

5 files changed

+8
-7
lines changed

include/linux/lockref.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
#define USE_CMPXCHG_LOCKREF \
2121
(IS_ENABLED(CONFIG_ARCH_USE_CMPXCHG_LOCKREF) && \
22-
IS_ENABLED(CONFIG_SMP) && !BLOATED_SPINLOCKS)
22+
IS_ENABLED(CONFIG_SMP) && SPINLOCK_SIZE <= 4)
2323

2424
struct lockref {
2525
union {

include/linux/mm.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1317,15 +1317,15 @@ static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long a
13171317
#endif /* CONFIG_MMU && !__ARCH_HAS_4LEVEL_HACK */
13181318

13191319
#if USE_SPLIT_PTE_PTLOCKS
1320-
#if BLOATED_SPINLOCKS
1320+
#if ALLOC_SPLIT_PTLOCKS
13211321
extern bool ptlock_alloc(struct page *page);
13221322
extern void ptlock_free(struct page *page);
13231323

13241324
static inline spinlock_t *ptlock_ptr(struct page *page)
13251325
{
13261326
return page->ptl;
13271327
}
1328-
#else /* BLOATED_SPINLOCKS */
1328+
#else /* ALLOC_SPLIT_PTLOCKS */
13291329
static inline bool ptlock_alloc(struct page *page)
13301330
{
13311331
return true;
@@ -1339,7 +1339,7 @@ static inline spinlock_t *ptlock_ptr(struct page *page)
13391339
{
13401340
return &page->ptl;
13411341
}
1342-
#endif /* BLOATED_SPINLOCKS */
1342+
#endif /* ALLOC_SPLIT_PTLOCKS */
13431343

13441344
static inline spinlock_t *pte_lockptr(struct mm_struct *mm, pmd_t *pmd)
13451345
{

include/linux/mm_types.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ struct address_space;
2626
#define USE_SPLIT_PTE_PTLOCKS (NR_CPUS >= CONFIG_SPLIT_PTLOCK_CPUS)
2727
#define USE_SPLIT_PMD_PTLOCKS (USE_SPLIT_PTE_PTLOCKS && \
2828
IS_ENABLED(CONFIG_ARCH_ENABLE_SPLIT_PMD_PTLOCK))
29+
#define ALLOC_SPLIT_PTLOCKS (SPINLOCK_SIZE > BITS_PER_LONG/8)
2930

3031
/*
3132
* Each physical page in the system has a struct page associated with
@@ -155,7 +156,7 @@ struct page {
155156
* system if PG_buddy is set.
156157
*/
157158
#if USE_SPLIT_PTE_PTLOCKS
158-
#if BLOATED_SPINLOCKS
159+
#if ALLOC_SPLIT_PTLOCKS
159160
spinlock_t *ptl;
160161
#else
161162
spinlock_t ptl;

kernel/bounds.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@ void foo(void)
2222
#ifdef CONFIG_SMP
2323
DEFINE(NR_CPUS_BITS, ilog2(CONFIG_NR_CPUS));
2424
#endif
25-
DEFINE(BLOATED_SPINLOCKS, sizeof(spinlock_t) > sizeof(int));
25+
DEFINE(SPINLOCK_SIZE, sizeof(spinlock_t));
2626
/* End of constants */
2727
}

mm/memory.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4271,7 +4271,7 @@ void copy_user_huge_page(struct page *dst, struct page *src,
42714271
}
42724272
#endif /* CONFIG_TRANSPARENT_HUGEPAGE || CONFIG_HUGETLBFS */
42734273

4274-
#if USE_SPLIT_PTE_PTLOCKS && BLOATED_SPINLOCKS
4274+
#if ALLOC_SPLIT_PTLOCKS
42754275
bool ptlock_alloc(struct page *page)
42764276
{
42774277
spinlock_t *ptl;

0 commit comments

Comments
 (0)