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 057DFEE7FE6 for ; Fri, 8 Sep 2023 12:38:49 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 641346B00BD; Fri, 8 Sep 2023 08:38:49 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5F0C66B00C0; Fri, 8 Sep 2023 08:38:49 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4B8BF6B00C1; Fri, 8 Sep 2023 08:38:49 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 389416B00BD for ; Fri, 8 Sep 2023 08:38:49 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 07463120C36 for ; Fri, 8 Sep 2023 12:38:49 +0000 (UTC) X-FDA: 81213384378.29.470F3E4 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf07.hostedemail.com (Postfix) with ESMTP id 6ADF940027 for ; Fri, 8 Sep 2023 12:38:46 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=kB5bXns9; spf=none (imf07.hostedemail.com: domain of peterz@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=peterz@infradead.org; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1694176727; 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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=xCpYqtznfwbFxqa9emaame4xf/442knA7YwfsM5Nb38=; b=n5FRyZpo3Hpm8LxKCdBElQO/hIea4CHpHRgP5yc08KqaU9bxx9YtOQD5l+bN77gpK2z3J1 p5C0FMdoL4UrIrVU6T56JlgRtecdp0mRZUzmjW6bkWkSQe9zYcQd437dYvyR+4BC/GAuaj Gi1bmHK1/idZp/ZCZICgflwjKeNe5Jc= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1694176727; a=rsa-sha256; cv=none; b=KFdiWp8KLcY9KPKhP6IwzzVjP3abHXN1LPTAV63Bp3HJRZoMwG8n6v2LJGPbyeAOcokypx g/mA1tPOAhu0wo9JWnJEnu0FnwHE7QvU378RS8RQsZQBCvNgycVSNe97CABOK+x0NEZZvU LgRV/zKyYDaaPvO25NXFo91nDF8MBT4= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=kB5bXns9; spf=none (imf07.hostedemail.com: domain of peterz@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=peterz@infradead.org; dmarc=none DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=xCpYqtznfwbFxqa9emaame4xf/442knA7YwfsM5Nb38=; b=kB5bXns9t0q+gY9eZbUlQaiRpV Gj7MzWSasDOMgn74WG5UGcn7mGR9iYrqujeEFHw92vhUN3yBd8+9cLbmAsUJkVddTrSAjtnugCERy 4+9lvmP/hKyTqQqG2aWUiPmOc/vtc7wdvsDb/X17gN/vgODy1q7cu2gY+yHiSvnve/1y6sem+UHii /D7gMozVR0t00DQXlQFIUXLSnOfXNi+BBiZqM41M7W9ifxb0jz8msaUpvCGZhwPUR8LwbAoREatuo gDXkmsia3RiWbLQKaXex6sSOVyDtsgM24NgQQcWO0oPX9v+C2OJ5sz+k3t5EfVQqbywwGrh0fFXYV J+h/JZLQ==; Received: from j130084.upc-j.chello.nl ([24.132.130.84] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1qeake-0009AV-0H; Fri, 08 Sep 2023 12:38:20 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 1000) id A7451300472; Fri, 8 Sep 2023 14:38:19 +0200 (CEST) Date: Fri, 8 Sep 2023 14:38:19 +0200 From: Peter Zijlstra To: Ankur Arora Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, x86@kernel.org, akpm@linux-foundation.org, luto@kernel.org, bp@alien8.de, dave.hansen@linux.intel.com, hpa@zytor.com, mingo@redhat.com, juri.lelli@redhat.com, vincent.guittot@linaro.org, willy@infradead.org, mgorman@suse.de, rostedt@goodmis.org, tglx@linutronix.de, jon.grimm@amd.com, bharata@amd.com, raghavendra.kt@amd.com, boris.ostrovsky@oracle.com, konrad.wilk@oracle.com Subject: Re: [PATCH v2 6/9] x86/clear_huge_page: multi-page clearing Message-ID: <20230908123819.GB19320@noisy.programming.kicks-ass.net> References: <20230830184958.2333078-1-ankur.a.arora@oracle.com> <20230830184958.2333078-7-ankur.a.arora@oracle.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230830184958.2333078-7-ankur.a.arora@oracle.com> X-Stat-Signature: nmiqk5he36p7y6nb3o4xcugr1kxxwtd5 X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 6ADF940027 X-Rspam-User: X-HE-Tag: 1694176726-118722 X-HE-Meta: U2FsdGVkX1+z5Cd8c0g76lPISk3axqH2DAywnG7cE26/pNC5vJTaCsljmPHJyQyOwuCgIahZSQMIpenSMvhMgCZXtFJpfQpNoO3Y6RI7ltcZt4LoatlwFejyW1QSJSKfsdGkgoAGvKAWtWRbkP3jtVM4Bb2uf5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.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Wed, Aug 30, 2023 at 11:49:55AM -0700, Ankur Arora wrote: > +#ifndef CONFIG_HIGHMEM I'm thinking this wants to be: #ifdef CONFIG_X86_64. All the previous stuff was 64bit specific. > +static void clear_contig_region(struct page *page, unsigned int npages) > +{ > + clear_pages(page_address(page), npages); > +} I'm not sure about the naming of this helper -- but whatever. > + > +/* > + * clear_huge_page(): multi-page clearing variant of clear_huge_page(). > + * > + * Taking inspiration from the common code variant, we split the zeroing in > + * three parts: left of the fault, right of the fault, and up to 5 pages > + * in the immediate neighbourhood of the target page. > + * > + * Cleared in that order to keep cache lines of the target region hot. > + * > + * For gigantic pages, there is no expectation of cache locality so we do a > + * straight zeroing. > + */ > +void clear_huge_page(struct page *page, > + unsigned long addr_hint, unsigned int pages_per_huge_page) > +{ > + unsigned long addr = addr_hint & > + ~(((unsigned long)pages_per_huge_page << PAGE_SHIFT) - 1); > + const long pgidx = (addr_hint - addr) / PAGE_SIZE; > + const int first_pg = 0, last_pg = pages_per_huge_page - 1; > + const int width = 2; /* pages cleared last on either side */ > + int sidx[3], eidx[3]; > + int i, n; > + > + if (pages_per_huge_page > MAX_ORDER_NR_PAGES) > + return clear_contig_region(page, pages_per_huge_page); > + > + /* > + * Neighbourhood of the fault. Cleared at the end to ensure > + * it sticks around in the cache. > + */ > + n = 2; > + sidx[n] = (pgidx - width) < first_pg ? first_pg : (pgidx - width); > + eidx[n] = (pgidx + width) > last_pg ? last_pg : (pgidx + width); > + > + sidx[0] = first_pg; /* Region to the left of the fault */ > + eidx[0] = sidx[n] - 1; > + > + sidx[1] = eidx[n] + 1; /* Region to the right of the fault */ > + eidx[1] = last_pg; > + > + for (i = 0; i <= 2; i++) { > + if (eidx[i] >= sidx[i]) > + clear_contig_region(page + sidx[i], > + eidx[i] - sidx[i] + 1); Since the if has a multi-line statement it needs { } per coding style. > + } > +} > +#endif /* CONFIG_HIGHMEM */ > #endif /* CONFIG_HUGETLB_PAGE */ > > #ifdef CONFIG_X86_64 > -- > 2.31.1 >