From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 94403C05027 for ; Fri, 17 Feb 2023 09:30:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 108596B0072; Fri, 17 Feb 2023 04:30:11 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 0B8D06B0073; Fri, 17 Feb 2023 04:30:11 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F10BC6B0074; Fri, 17 Feb 2023 04:30:10 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id E2EDA6B0072 for ; Fri, 17 Feb 2023 04:30:10 -0500 (EST) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 530B41C6EF3 for ; Fri, 17 Feb 2023 09:30:10 +0000 (UTC) X-FDA: 80476262580.18.4D38800 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by imf16.hostedemail.com (Postfix) with ESMTP id 1BD1618000B for ; Fri, 17 Feb 2023 09:30:07 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=S4Klg0HI; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=nYpr4daA; spf=pass (imf16.hostedemail.com: domain of vbabka@suse.cz designates 195.135.220.29 as permitted sender) smtp.mailfrom=vbabka@suse.cz; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1676626208; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=scYh//7n4UiKTBLeV1t9pIL7YuyPxKt/8nZ35rpMs4Y=; b=akIHvLEF++b2b5TYilAYik2hb8mvD1vJ/cJHL6jhZ4kxrKQtW5NSAwTDfZhkIEAsRtmuap veKQDbc9RvjVwglPA/qcT6cR7Qq6m+VuZUEF5WMsv9NBvEoSg/yqkbxjNc0VzHZcoSORfY FJJB6Oxg3H4JWDme2ERMLWIhAA1zWes= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=S4Klg0HI; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=nYpr4daA; spf=pass (imf16.hostedemail.com: domain of vbabka@suse.cz designates 195.135.220.29 as permitted sender) smtp.mailfrom=vbabka@suse.cz; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1676626208; a=rsa-sha256; cv=none; b=sCTAK2f4S2rMPOgVWpQQh9M2+vxuG9wbIEoQgVwY/ojpjMcXYxigXKMu1QqGqXLxU+Z4RR T5Ufb8IQPG9L9VlbvlAWDbA++hTCGYT9qByjTAFEtunpnH3TXf2ktza4f/FSLjzxLRZniQ OubOEJ0fdAMpuOzTcF7jmgOmrXE3eeA= Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 581931FDC1; Fri, 17 Feb 2023 09:30:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1676626206; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=scYh//7n4UiKTBLeV1t9pIL7YuyPxKt/8nZ35rpMs4Y=; b=S4Klg0HI5jyVWLSwmzrGFSSFPi00vtRFxNV59BfMJecder+ozW8oI28WuXg/HxU18Xv4LE S4xbiMINcymc5r43IksMMzlhmd2dVDjBGGiXvFwmH6p3np4AVz4fYi8BGFk31eE9kDFhl3 H1a8GQ++wTBJjKFdQWDjcCo3OoOwnlQ= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1676626206; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=scYh//7n4UiKTBLeV1t9pIL7YuyPxKt/8nZ35rpMs4Y=; b=nYpr4daAyNGwQbRH+NZBJuYebacl7yicFA7SsIs8ueMglsuj6cNMgviwylTQMmRTXI2864 Co6zAFkxwY2hS8Cw== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 4031D138E3; Fri, 17 Feb 2023 09:30:06 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id zFQGDx5J72M1FgAAMHmgww (envelope-from ); Fri, 17 Feb 2023 09:30:06 +0000 Message-ID: Date: Fri, 17 Feb 2023 10:30:05 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.7.1 Subject: Re: [net PATCH 1/2] mm: Use fixed constant in page_frag_alloc instead of size + 1 To: Alexander Duyck , netdev@vger.kernel.org, davem@davemloft.net Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, jannh@google.com References: <20190215223741.16881.84864.stgit@localhost.localdomain> <20190215224412.16881.89296.stgit@localhost.localdomain> Content-Language: en-US From: Vlastimil Babka In-Reply-To: <20190215224412.16881.89296.stgit@localhost.localdomain> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 1BD1618000B X-Rspam-User: X-Stat-Signature: quaofu6exur7iwq3de6fnqcgqacwikep X-HE-Tag: 1676626207-288588 X-HE-Meta: U2FsdGVkX1/e1VOiZMtr4rPbyXwh+smRiHZwRXtoQD7zAi7gFEZdq+ID6EXitLDocUHknbmAKOg4XQykjR5/+FY9RSrHUD1koqHNzDMWWch5w7SyuoBDH2gJkZa1rUaYjviivm87o6P9R36brm16tG7wTrSzkQmY+kI6ghIR7M2+vnKdVtYaY/lshfYOdbRHuJ8W4zmEg/dUC74tm3Wjd+23+rVHPZr3l7JcazujKn4dF+44SVVYTu/BjEcwxbtewz7M9k9IrZcl4B5isp9Uy7Ks8HlevB/28NWi/tk0AI04ofHHWNElaWEatUs4HAI2tLgXX8w/d4mLuF4+50BzoRfMRv0rMztYcNLyMinIYhZOWC2TNV+KjsEchtrIZeudhJAenii5oeTAgdgPWK0y05OZfQku/Vb9sVHCrcz7RI4SU2o6XYgp1jv/sxqf0pfNwAZ5KjOIoKn/oKh7sXzDyLNIUxdnDfxjmxxA5Ow6aS7c0kVHH3tv+XV23hz9GRjC7afqu8h5RD1iP2esBh6H6EFdChE/iY/KWsq8NMr4ZKAinG7zsABEYO8F35Cn0nrggUtRWrmAMELeJgrUWUgKyqvQrC9BMTulUQbSJNkyZp0+smA+IYh9JUe3obRNZf7I5SaBTBWZ4au604TZuScdMHvT+L8qxBsd+EMPwaW5BTTPoGHhEG2/T4So6bjIDbAwBcvZj3Tv/++DPigumAaU5al4jhpMtjdbUelz3u5umF80iU1vgzkexszKe2rBxXr7teXdh2qovtMZ8RgQrwAQ4t6dJB261XjJC/igTDwQdlpL9HAVPUA7mWhtOL709d4gOtBmY95n5F/9ZwzG/liKUzZiUXMHnjrVq39U6o8jkAPq0DVVadqgNBm/PEbw44hTdihxR0uvIob2GpEPmgEzVoVORrS7Ykn3P2rVA+/+6P9bpvmHH6QaOGsNrndzMkmSjnbGgdD4f7uAliUS5uO wDfw6VFf +vcErz4Heus1OgJNrFhC4kcy6W4GA+KE36CiV5ea6VrHN4/ue7Br1N895ZbHAGKVOnVdaxwsjoYgQ7OV1vaUiRXm/iISvFMPA/Jgqj9XF6o/8uU6l2Mlmvjjq3k/xojdArM/sFS/Cfxzva0y3+V1LV+2fgSl910DhXhGcJy86sYEzNBLfu/F4AQzn6Otn8xRByKdoHXTrvvv98pUI0eV/7ggYcb/xGg3O6QS2yjRBAizdmJg2GWhutEdCUp7GESuyww1YCEYtn4sVtp2Bm/p0O35S86KoKMD56CZpcOcppdBzDgh3I60aUzJLHPdiY9+jopgr7Y1Ul5TeiFKAy3yP1Ikq4/ZQCxFoYca525rI07Wp406xvAfkTRZgtNvVNi5qKKhirZe+kq9lfxW+KAoGrzDyZcQ3dFVXcp3V X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On 2/15/19 23:44, Alexander Duyck wrote: > From: Alexander Duyck > > This patch replaces the size + 1 value introduced with the recent fix for 1 > byte allocs with a constant value. > > The idea here is to reduce code overhead as the previous logic would have > to read size into a register, then increment it, and write it back to > whatever field was being used. By using a constant we can avoid those > memory reads and arithmetic operations in favor of just encoding the > maximum value into the operation itself. > > Fixes: 2c2ade81741c ("mm: page_alloc: fix ref bias in page_frag_alloc() for 1-byte allocs") > Signed-off-by: Alexander Duyck > --- > mm/page_alloc.c | 8 ++++---- > 1 file changed, 4 insertions(+), 4 deletions(-) > > diff --git a/mm/page_alloc.c b/mm/page_alloc.c > index ebb35e4d0d90..37ed14ad0b59 100644 > --- a/mm/page_alloc.c > +++ b/mm/page_alloc.c > @@ -4857,11 +4857,11 @@ void *page_frag_alloc(struct page_frag_cache *nc, > /* Even if we own the page, we do not use atomic_set(). > * This would break get_page_unless_zero() users. > */ > - page_ref_add(page, size); > + page_ref_add(page, PAGE_FRAG_CACHE_MAX_SIZE); But this value can be theoretically too low when PAGE_SIZE > PAGE_FRAG_CACHE_MAX_SIZE? Such as on architectures with 64kB page size, while PAGE_FRAG_CACHE_MAX_SIZE is 32kB? Maybe impossible to exploit in practice thanks to the minimum alignment, but still IMHO we should be using the larger of PAGE_FRAG_CACHE_MAX_SIZE and PAGE_SIZE, which should still be a build-time constant, so not defeat the optimization. > > /* reset page count bias and offset to start of new frag */ > nc->pfmemalloc = page_is_pfmemalloc(page); > - nc->pagecnt_bias = size + 1; > + nc->pagecnt_bias = PAGE_FRAG_CACHE_MAX_SIZE + 1; > nc->offset = size; > } > > @@ -4877,10 +4877,10 @@ void *page_frag_alloc(struct page_frag_cache *nc, > size = nc->size; > #endif > /* OK, page count is 0, we can safely set it */ > - set_page_count(page, size + 1); > + set_page_count(page, PAGE_FRAG_CACHE_MAX_SIZE + 1); > > /* reset page count bias and offset to start of new frag */ > - nc->pagecnt_bias = size + 1; > + nc->pagecnt_bias = PAGE_FRAG_CACHE_MAX_SIZE + 1; > offset = size - fragsz; > } > >