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 1F587C433F5 for ; Fri, 26 Nov 2021 06:54:57 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8EFC66B0075; Fri, 26 Nov 2021 01:54:46 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 89FEA6B0078; Fri, 26 Nov 2021 01:54:46 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 78E7D6B007B; Fri, 26 Nov 2021 01:54:46 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0040.hostedemail.com [216.40.44.40]) by kanga.kvack.org (Postfix) with ESMTP id 6A3B16B0075 for ; Fri, 26 Nov 2021 01:54:46 -0500 (EST) Received: from smtpin30.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 311351848F030 for ; Fri, 26 Nov 2021 06:54:36 +0000 (UTC) X-FDA: 78850168152.30.AB8E3C4 Received: from mail-ed1-f45.google.com (mail-ed1-f45.google.com [209.85.208.45]) by imf22.hostedemail.com (Postfix) with ESMTP id 0D3B9190F for ; Fri, 26 Nov 2021 06:54:34 +0000 (UTC) Received: by mail-ed1-f45.google.com with SMTP id y12so34583633eda.12 for ; Thu, 25 Nov 2021 22:54:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=H19UTR6A3kWJJtvYx5Y6mT7M01EqlCEK84X1kiQHMws=; b=bqxUG9GBwRxXusR0vQDwXIKE6tmcfVDsDscQDKgRdXOuIiQDmox3u/A8r0+NArAguX ryOAq6uwAHZira08kD6Pu7FjfRAqNG2Lw8IkeSjlPR20UPa9uslZ6fEl85gCwOfaY2+Z JvMMepT01lYXH6+p4Uc9HYYV7u0SXQwJ+cyxy4xHteJGk6Q61AlBs+kNfMFNkrbhpSmc ugm+v0S6yqERyuaNatOq9swdrMA1oXVgA3qcsRD2bkC+DUc/bmeIIh/7UpPKWVJoGPnr HSyCu7ECVTvXK1zs/ZvsEXHuU4LJSFp1p/J3gouteiUm/d9gBdoMZec9azTWVnnlofkV 8mFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=H19UTR6A3kWJJtvYx5Y6mT7M01EqlCEK84X1kiQHMws=; b=FP2g4vmddL0jHDH8kjYmCMkJJkl29UtIblz+YawFDnUBlSYwmdBJ40cGW7lZ/AGuoZ B/hRKP1hYkvO6+Wzh11puYAu28lJrYTcyGnJtB0yJi9wS3sKmi6z+tn4LsBUGOWHI4IX 4Ykqz+wQcclHM02ABhDO9CHXZRuALWd+V3ZhayQaFmuum8CvLDwkg06my8b0LGJjzNLk rQxDXKw1i9PsPkkANsiGAZpH5XwKFE274HYvi7+R1s0CoI4unsxexcT/0ttpcr/B/KTl /yiIjajrzfPIzdMn2pxyJ7GHhsjEW+MRgotH1gJJS4/r32u/Ag0sMURQO2lUYi6suG7I dG6A== X-Gm-Message-State: AOAM532bAxWbMQQzFSewyQdC3zEBedogh8fmv5Z8C4mtp9xKCPL5yurk A0DtTPdjBzPDpC5chS5ntlRCfLRvlTGCn3nXIH2J1EXjIx5iRzMX X-Google-Smtp-Source: ABdhPJxs0IPvPnqp3NBCU2rei0wRCuf8DbXNhGodW3vBcZa4EIEe4pIsjnkZ2X/CJLloy+mGOw6/PG0KgQ7sW9JeyV0= X-Received: by 2002:a05:6402:84f:: with SMTP id b15mr44196111edz.323.1637909674456; Thu, 25 Nov 2021 22:54:34 -0800 (PST) MIME-Version: 1.0 References: <20211124151915.GA6163@haolee.io> <20211125080238.GA7356@haolee.io> In-Reply-To: From: Hao Lee Date: Fri, 26 Nov 2021 14:54:23 +0800 Message-ID: Subject: Re: [PATCH] mm: reduce spinlock contention in release_pages() To: Matthew Wilcox Cc: Michal Hocko , Linux MM , Johannes Weiner , vdavydov.dev@gmail.com, Shakeel Butt , cgroups@vger.kernel.org, LKML Content-Type: text/plain; charset="UTF-8" X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 0D3B9190F Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=bqxUG9GB; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf22.hostedemail.com: domain of haolee.swjtu@gmail.com designates 209.85.208.45 as permitted sender) smtp.mailfrom=haolee.swjtu@gmail.com X-Stat-Signature: h576qynzwsx4s49q6x9uiftuk5jfw3me X-HE-Tag: 1637909674-89399 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 Fri, Nov 26, 2021 at 2:04 AM Matthew Wilcox wrote: > > 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. Exactly. > > Your use-case doesn't seem to mind sleeping (after all, these processes > are exiting). Yes! > 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. This is really a good idea. My train of thought was trapped in reducing the lock contention. I will try to implement this idea and see if the service stability will be improved much. Thanks for your help!