From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-172.mta1.migadu.com (out-172.mta1.migadu.com [95.215.58.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A2381331ED8 for ; Thu, 9 Jul 2026 14:24:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783607067; cv=none; b=PTpESylG2z3Cc1mMF9jeogGbIQ8aPlKp98wC7Kn99zhiWXJ/s41gyHSjQzhb1aUXjAb6RFEdLkcoi9FdUc3MSeOyVrmh7yCC9alODfYRXXgzAeC1fVjojh2ljAFzcaEVMLUcF5hrMQJ/+GFGtdYdI6uEu2papvLb4iY0CBxRoMA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783607067; c=relaxed/simple; bh=tIHEGyT5ldvtsed8frzfaU4agFhwf0M8sm55kkXf0oA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hX/tatlwsIGUloMHJ8F0oBSdLGTJPWpvwTvmTp8TskfcACBkQkccPwkRWvh+lmYbfSAe1ybd8Td9gqx2UfiPzrtQk9ocuDXLFpbnaxxR04BEN5XqCiLwYQXQwWqtYE6jLM3pmsqUpqGrhjrEWnOP9B0kQ4NOO8m3vBzPA0whzu4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=Btk+aZVn; arc=none smtp.client-ip=95.215.58.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="Btk+aZVn" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1783607062; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=EUy+Ri2pT7wvVY/ajX0BV3e3H7R/seUWuMeezghtcHk=; b=Btk+aZVnVrfetD0/oZcoqxzqskUtquanN86nBAQQy2GMIakYKxG6K18qS76Eb9X434e39/ TvJH+sZo7/dtDfDgg+nTqQa5FHgW7AALn/bO2K+ZBt7ZDy5exPzUJd+zdv2IRElB9yMvXd Q9FVDnwysjJC2HD9vFL2xq2PDCIZK9k= From: Usama Arif To: Usama Arif Cc: Andrew Morton , david@kernel.org, ljs@kernel.org, liam@infradead.org, vbabka@kernel.org, rppt@kernel.org, surenb@google.com, mhocko@suse.com, kasong@tencent.com, qi.zheng@linux.dev, shakeel.butt@linux.dev, axelrasmussen@google.com, yuanchu@google.com, weixugc@google.com, chrisl@kernel.org, nphamcs@gmail.com, baoquan.he@linux.dev, youngjun.park@lge.com, hannes@cmpxchg.org, roman.gushchin@linux.dev, muchun.song@linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, rientjes@google.com, kernel-team@meta.com Subject: Re: [PATCH 0/1] mm/vmscan: reduce lru_lock contention via vmstat-derived scan-balance cost Date: Thu, 9 Jul 2026 07:24:11 -0700 Message-ID: <20260709142412.91707-1-usama.arif@linux.dev> In-Reply-To: <20260706122954.3552990-1-usama.arif@linux.dev> References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT On Mon, 6 Jul 2026 05:28:25 -0700 Usama Arif wrote: > The anon/file scan balance heuristic in get_scan_count() is fed by two > scalars in struct lruvec (anon_cost, file_cost) that every reclaim > producer updates under lruvec->lru_lock. The cost-recording work > itself is trivial, but it both contends for and contributes to > contention on lru_lock - which is often a contention point on > memory-pressured workloads. Specifically: > > - shrink_inactive_list() re-acquires lru_lock at function exit just > to call lru_note_cost_unlock_irq(). > - shrink_active_list() does the same after rotation accounting. > - workingset_refault() takes folio_lruvec_lock_irq() purely to > record the refault cost. > - prepare_scan_control() snapshots anon_cost/file_cost under > lru_lock. > - lru_note_cost_unlock_irq() itself walks parent_lruvec() and > re-acquires lru_lock on every ancestor, multiplying the cost > of every update by memcg-hierarchy depth. > > This patch removes those producer-side acquisitions entirely. The > producer-local inputs (PGROTATE_*, PGRECLAIM_PAGEOUT_*) become > per-LRU vmstat counters; WORKINGSET_RESTORE_* already captures the > refault input. prepare_scan_control() reads the raw cost signal > lock-free from those vmstats and folds the delta into a per-lruvec > accumulator. A dedicated per-lruvec cost_lock, not touched by > isolate_lru_folios(), move_folios_to_lru(), or folio_add_lru(), > serialises the accumulator RMW and the lrusize/4 halving check. > Hierarchy aggregation is implicit in rstat propagation, so the > parent_lruvec() walk and the lru_reparent_memcg() cost-splice both > disappear. Another update on this, I was profiling another Meta workload that suffers from very heavy reclaim and has a lot of cgroups. I ran: bpftrace -q -e 'profile:hz:99 { @[kstack, comm] = count(); }' The biggest entry was below: @[ lru_note_cost_unlock_irq+146 shrink_lruvec+1913 shrink_node+869 do_try_to_free_pages+197 try_to_free_mem_cgroup_pages+311 __mem_cgroup_charge+1832 filemap_add_folio+127 page_cache_ra_unbounded+347 filemap_fault+956 __do_fault+40 handle_mm_fault+4034 do_user_addr_fault+406 exc_page_fault+105 asm_exc_page_fault+34 , Func___]: 5354 5354 represents 51.42% of all kernel samples collected. A very signifcant amount of time was being spent just in lru_note_cost_unlock_irq