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 DE887C433F5 for ; Thu, 25 Nov 2021 18:04:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6AB466B009A; Thu, 25 Nov 2021 13:04:35 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 6347E6B009C; Thu, 25 Nov 2021 13:04:35 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4D5CF6B009D; Thu, 25 Nov 2021 13:04:35 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0057.hostedemail.com [216.40.44.57]) by kanga.kvack.org (Postfix) with ESMTP id 364886B009A for ; Thu, 25 Nov 2021 13:04:35 -0500 (EST) Received: from smtpin12.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id ECB72182C04D6 for ; Thu, 25 Nov 2021 18:04:24 +0000 (UTC) X-FDA: 78848227248.12.EAF274A Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf25.hostedemail.com (Postfix) with ESMTP id 7C181B000316 for ; Thu, 25 Nov 2021 18:04:07 +0000 (UTC) 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=l6gSn5dJkbwR5eJQa8fzZhyhrJULSWQHB9aANYgp6/s=; b=jdpn6IPgL/qCmFXmED9gghg6p2 MFJD68+hWmud09MHPE3po5nbXJiHs8DkhCjlSlTrxJgVQhNU9hxP5oopJK/TRSdI+Ci+GBJFdgHj9 B1y1BV16F0flpMBh6zWUbCkRz+qtJCAOYqzMnylwl6rirO63BRmw0Fgayh7WJCc2SmJX4iF5q6dbf hZxNWxQ2oxeLEIX+ypnm99o22WRjJ4b54Pxtg918D8++DhRL2G7RbmSyvVeq1BHKyrYUIjofyeQ0E B/aYpLCeuqLuQtXdTfC1FZXn+6XajNp/lOMdaTcSeUYsxL3Owz1fLs/iHOQoJzxNiL8p+OsO/ZfsP vZN1JGEw==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1mqJ6L-007Ggn-UM; Thu, 25 Nov 2021 18:04:05 +0000 Date: Thu, 25 Nov 2021 18:04:05 +0000 From: Matthew Wilcox To: Hao Lee Cc: Michal Hocko , Linux MM , Johannes Weiner , vdavydov.dev@gmail.com, Shakeel Butt , cgroups@vger.kernel.org, LKML Subject: Re: [PATCH] mm: reduce spinlock contention in release_pages() Message-ID: References: <20211124151915.GA6163@haolee.io> <20211125080238.GA7356@haolee.io> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20211125080238.GA7356@haolee.io> X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 7C181B000316 X-Stat-Signature: corh8pdqj5j7ypzrsk5hw3sowm1ecxgm Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=jdpn6IPg; spf=none (imf25.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none X-HE-Tag: 1637863447-863500 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 Thu, Nov 25, 2021 at 08:02:38AM +0000, Hao Lee wrote: > On Thu, Nov 25, 2021 at 03:30:44AM +0000, Matthew Wilcox wrote: > > On Thu, Nov 25, 2021 at 11:24:02AM +0800, Hao Lee wrote: > > > On Thu, Nov 25, 2021 at 12:31 AM Michal Hocko wrote: > > > > We do batch currently so no single task should be > > > > able to monopolize the cpu for too long. Why this is not sufficient? > > > > > > uncharge and unref indeed take advantage of the batch process, but > > > del_from_lru needs more time to complete. Several tasks will contend > > > spinlock in the loop if nr is very large. > > > > Is SWAP_CLUSTER_MAX too large? Or does your architecture's spinlock > > implementation need to be fixed? > > > > My testing server is x86_64 with 5.16-rc2. The spinlock should be normal. > > I think lock_batch is not the point. lock_batch only break spinning time > into small parts, but it doesn't reduce spinning time. The thing may get > worse if lock_batch is very small. OK. So if I understand right, you've got a lot of processes all calling exit_mmap() at the same time, which eventually becomes calls to unmap_vmas(), unmap_single_vma(), unmap_page_range(), zap_pte_range(), tlb_flush_mmu(), tlb_batch_pages_flush(), free_pages_and_swap_cache(), release_pages(), and then you see high contention on the LRU lock. Your use-case doesn't seem to mind sleeping (after all, these processes are exiting). So we could put a semaphore in exit_mmap() to limit the number of simultaneous callers to unmap_vmas(). Do you want to try that out and see if it solves your problem? You might want to make it a counting semaphore (eg permit two tasks to exit at once) rather than a mutex. But maybe a mutex is just fine.