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 D664DC77B7C for ; Fri, 5 May 2023 00:54:47 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3CC196B0075; Thu, 4 May 2023 20:54:47 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 37C366B0078; Thu, 4 May 2023 20:54:47 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 293D06B007B; Thu, 4 May 2023 20:54:47 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by kanga.kvack.org (Postfix) with ESMTP id F193D6B0075 for ; Thu, 4 May 2023 20:54:46 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1683248087; x=1714784087; h=from:to:cc:subject:references:date:in-reply-to: message-id:mime-version; bh=C8RdFdrJlwbwRJXfOC+j8Nx0S28v8fPzkihiJlQcOfg=; b=LFNlN0pl+iYpkZieNDRw/7jt65rIed4E5pv6EFhg6uMVNWawJ6mq58wI AHMThzYUZXgMubzRb0PY2sLKSkLp/lt6kBvVtQrSVybYsRZOpX2+vf8lw NDb+JZwVSiDYKOGZt5BKX+3QDCue4QDSR1KM+ZdOrpn9sybOk4Lp8IsJV KDtMiTVhFf5MBNbLJGG1vz0KfJx381uQZi+nxS9ITlHI7wuwaFEBMBlUc Od+Uvrq7+3ngZywN4FsAuVWb0e39bzhhuNHVjlOjSs7f3fwZRGwKwVWLx 1DbBHvOSMn3Geie5ndhqsQT7u4Z81rM7rJeY/sw47CN4zJcZoZXiQJ9FI g==; X-IronPort-AV: E=McAfee;i="6600,9927,10700"; a="414621617" X-IronPort-AV: E=Sophos;i="5.99,250,1677571200"; d="scan'208";a="414621617" Received: from orsmga004.jf.intel.com ([10.7.209.38]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 May 2023 17:54:45 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10700"; a="821424079" X-IronPort-AV: E=Sophos;i="5.99,250,1677571200"; d="scan'208";a="821424079" Received: from yhuang6-desk2.sh.intel.com (HELO yhuang6-desk2.ccr.corp.intel.com) ([10.238.208.55]) by orsmga004-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 May 2023 17:54:43 -0700 From: "Huang, Ying" To: Yin Fengwei Cc: , , , , , Subject: Re: [PATCH v3 1/2] THP: avoid lock when check whether THP is in deferred list References: <20230429082759.1600796-1-fengwei.yin@intel.com> <20230429082759.1600796-2-fengwei.yin@intel.com> Date: Fri, 05 May 2023 08:52:37 +0800 In-Reply-To: <20230429082759.1600796-2-fengwei.yin@intel.com> (Yin Fengwei's message of "Sat, 29 Apr 2023 16:27:58 +0800") Message-ID: <877ctnd2ga.fsf@yhuang6-desk2.ccr.corp.intel.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=ascii 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: Yin Fengwei writes: > free_transhuge_page() acquires split queue lock then check > whether the THP was added to deferred list or not. It brings > high deferred queue lock contention. > > It's safe to check whether the THP is in deferred list or not > without holding the deferred queue lock in free_transhuge_page() > because when code hit free_transhuge_page(), there is no one > tries to add the folio to _deferred_list. > > Running page_fault1 of will-it-scale + order 2 folio for anonymous > mapping with 96 processes on an Ice Lake 48C/96T test box, we could > see the 61% split_queue_lock contention: > - 63.02% 0.01% page_fault1_pro [kernel.kallsyms] [k] free_transhuge_page > - 63.01% free_transhuge_page > + 62.91% _raw_spin_lock_irqsave > > With this patch applied, the split_queue_lock contention is less > than 1%. > > Signed-off-by: Yin Fengwei Thanks! Reviewed-by: "Huang, Ying" > --- > mm/huge_memory.c | 17 ++++++++++++----- > 1 file changed, 12 insertions(+), 5 deletions(-) > > diff --git a/mm/huge_memory.c b/mm/huge_memory.c > index 032fb0ef9cd1..2a1df2c24c8e 100644 > --- a/mm/huge_memory.c > +++ b/mm/huge_memory.c > @@ -2799,12 +2799,19 @@ void free_transhuge_page(struct page *page) > struct deferred_split *ds_queue = get_deferred_split_queue(folio); > unsigned long flags; > > - spin_lock_irqsave(&ds_queue->split_queue_lock, flags); > - if (!list_empty(&folio->_deferred_list)) { > - ds_queue->split_queue_len--; > - list_del(&folio->_deferred_list); > + /* > + * At this point, there is no one trying to add the folio to > + * deferred_list. If folio is not in deferred_list, it's safe > + * to check without acquiring the split_queue_lock. > + */ > + if (data_race(!list_empty(&folio->_deferred_list))) { > + spin_lock_irqsave(&ds_queue->split_queue_lock, flags); > + if (!list_empty(&folio->_deferred_list)) { > + ds_queue->split_queue_len--; > + list_del(&folio->_deferred_list); > + } > + spin_unlock_irqrestore(&ds_queue->split_queue_lock, flags); > } > - spin_unlock_irqrestore(&ds_queue->split_queue_lock, flags); > free_compound_page(page); > }