lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20190224092838.3417-1-peng.fan@nxp.com>
Date:   Sun, 24 Feb 2019 09:17:08 +0000
From:   Peng Fan <peng.fan@....com>
To:     "dennis@...nel.org" <dennis@...nel.org>,
        "tj@...nel.org" <tj@...nel.org>, "cl@...ux.com" <cl@...ux.com>
CC:     "linux-mm@...ck.org" <linux-mm@...ck.org>,
        "linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
        "van.freenix@...il.com" <van.freenix@...il.com>,
        Peng Fan <peng.fan@....com>
Subject: [RFC] percpu: decrease pcpu_nr_slots by 1

Entry pcpu_slot[pcpu_nr_slots - 2] is wasted with current code logic.
pcpu_nr_slots is calculated with `__pcpu_size_to_slot(size) + 2`.
Take pcpu_unit_size as 1024 for example, __pcpu_size_to_slot will
return max(11 - PCPU_SLOT_BASE_SHIFT + 2, 1), it is 8, so the
pcpu_nr_slots will be 10.

The chunk with free_bytes 1024 will be linked into pcpu_slot[9].
However free_bytes in range [512,1024) will be linked into
pcpu_slot[7], because `fls(512) - PCPU_SLOT_BASE_SHIFT + 2` is 7.
So pcpu_slot[8] is has no chance to be used.

According comments of PCPU_SLOT_BASE_SHIFT, 1~31 bytes share the same slot
and PCPU_SLOT_BASE_SHIFT is defined as 5. But actually 1~15 share the
same slot 1 if we not take PCPU_MIN_ALLOC_SIZE into consideration, 16~31
share slot 2. Calculation as below:
highbit = fls(16) -> highbit = 5
max(5 - PCPU_SLOT_BASE_SHIFT + 2, 1) equals 2, not 1.

This patch by decreasing pcpu_nr_slots to avoid waste one slot and
let [PCPU_MIN_ALLOC_SIZE, 31) really share the same slot.

Signed-off-by: Peng Fan <peng.fan@....com>
---

V1:
 Not very sure about whether it is intended to leave the slot there.

 mm/percpu.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/mm/percpu.c b/mm/percpu.c
index 8d9933db6162..12a9ba38f0b5 100644
--- a/mm/percpu.c
+++ b/mm/percpu.c
@@ -219,7 +219,7 @@ static bool pcpu_addr_in_chunk(struct pcpu_chunk *chunk, void *addr)
 static int __pcpu_size_to_slot(int size)
 {
 	int highbit = fls(size);	/* size is in bytes */
-	return max(highbit - PCPU_SLOT_BASE_SHIFT + 2, 1);
+	return max(highbit - PCPU_SLOT_BASE_SHIFT + 1, 1);
 }
 
 static int pcpu_size_to_slot(int size)
@@ -2145,7 +2145,7 @@ int __init pcpu_setup_first_chunk(const struct pcpu_alloc_info *ai,
 	 * Allocate chunk slots.  The additional last slot is for
 	 * empty chunks.
 	 */
-	pcpu_nr_slots = __pcpu_size_to_slot(pcpu_unit_size) + 2;
+	pcpu_nr_slots = __pcpu_size_to_slot(pcpu_unit_size) + 1;
 	pcpu_slot = memblock_alloc(pcpu_nr_slots * sizeof(pcpu_slot[0]),
 				   SMP_CACHE_BYTES);
 	for (i = 0; i < pcpu_nr_slots; i++)
-- 
2.16.4

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ