From nobody Wed Nov 27 14:36:00 2024 Received: from SHSQR01.spreadtrum.com (unknown [222.66.158.135]) (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 613C917C7A3 for ; Wed, 9 Oct 2024 07:50:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=222.66.158.135 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728460260; cv=none; b=cXbFPCt8yz1LyJf8xdIzQrgvuVAPrgtnXl8aenGnwZyckuFpuZw3V8s9MPMd+8g3LlcRXIsVtQoxdy2PNy7f8k0+LVIxwg+oiSW9jmNXHhknag+ic5CU6AtGHuehT6ogkUtLR/bzDvKWjPqOtz46PqWR4DIkDSQxsY1D1guq/cg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728460260; c=relaxed/simple; bh=6OOVqlOk9icEHZcCVArVCU/dmE92U6L/nULwjwBah7I=; h=From:To:Subject:Date:Message-ID:MIME-Version:Content-Type; b=sQp54G7gWGFR56CXTJuAIdw3VmQ2sogo5Gnd+zg0qQnAqJdTTocPgLr+hsRK/SADmMPV2DWZAVIDJ5xiR6mTsB/fX4ZmASzSDPLvsxrcxvPorBYSdDb69inTB4xMCvXNVRQ1NQ6g/ikMXqWm8Pbek+Wup51qCLCVqhmWAhShmpM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=unisoc.com; spf=pass smtp.mailfrom=unisoc.com; arc=none smtp.client-ip=222.66.158.135 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=unisoc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=unisoc.com Received: from dlp.unisoc.com ([10.29.3.86]) by SHSQR01.spreadtrum.com with ESMTP id 4997oJR8056751; Wed, 9 Oct 2024 15:50:19 +0800 (+08) (envelope-from zhaoyang.huang@unisoc.com) Received: from SHDLP.spreadtrum.com (bjmbx01.spreadtrum.com [10.0.64.7]) by dlp.unisoc.com (SkyGuard) with ESMTPS id 4XNlG63rdRz2PD1VF; Wed, 9 Oct 2024 15:42:06 +0800 (CST) Received: from bj03382pcu01.spreadtrum.com (10.0.73.40) by BJMBX01.spreadtrum.com (10.0.64.7) with Microsoft SMTP Server (TLS) id 15.0.1497.23; Wed, 9 Oct 2024 15:50:16 +0800 From: "zhaoyang.huang" To: Andrew Morton , Yu Zhao , , , Zhaoyang Huang , Subject: [PATCH] mm: throttle and inc min_seq when both page types reach MIN_NR_GENS Date: Wed, 9 Oct 2024 15:49:53 +0800 Message-ID: <20241009074953.608591-1-zhaoyang.huang@unisoc.com> X-Mailer: git-send-email 2.25.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: SHCAS03.spreadtrum.com (10.0.1.207) To BJMBX01.spreadtrum.com (10.0.64.7) X-MAIL: SHSQR01.spreadtrum.com 4997oJR8056751 Content-Type: text/plain; charset="utf-8" From: Zhaoyang Huang The test case of [1] leads to system hang which caused by a local watchdog thread starved over 20s on a 5.5GB RAM ANDROID15(v6.6) system. This commit solve the issue by have the reclaimer be throttled and increase min_seq if both page types reach MIN_NR_GENS, which may introduce a livelock of switching type with holding lruvec->lru_lock. [1] launch below script 8 times simutanously which allocates 1GB virtual memory and access it from user space by each thread. $ costmem -c1024000 -b12800 -o0 & Signed-off-by: Zhaoyang Huang --- mm/vmscan.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/mm/vmscan.c b/mm/vmscan.c index cfa839284b92..83e450d0ce3c 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -4384,11 +4384,23 @@ static int scan_folios(struct lruvec *lruvec, struc= t scan_control *sc, int remaining =3D MAX_LRU_BATCH; struct lru_gen_folio *lrugen =3D &lruvec->lrugen; struct mem_cgroup *memcg =3D lruvec_memcg(lruvec); + struct pglist_data *pgdat =3D lruvec_pgdat(lruvec); =20 VM_WARN_ON_ONCE(!list_empty(list)); =20 - if (get_nr_gens(lruvec, type) =3D=3D MIN_NR_GENS) - return 0; + if (get_nr_gens(lruvec, type) =3D=3D MIN_NR_GENS) { + /* + * throttle for a while and then increase the min_seq since + * both page types reach the limit. + */ + if (get_nr_gens(lruvec, !type) =3D=3D MIN_NR_GENS) { + spin_unlock_irq(&lruvec->lru_lock); + reclaim_throttle(pgdat, VMSCAN_THROTTLE_ISOLATED); + spin_lock_irq(&lruvec->lru_lock); + try_to_inc_min_seq(lruvec, get_swappiness(lruvec, sc)); + } else + return 0; + } =20 gen =3D lru_gen_from_seq(lrugen->min_seq[type]); =20 --=20 2.25.1