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 73831C2BBCA for ; Tue, 25 Jun 2024 22:14:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B81336B007B; Tue, 25 Jun 2024 18:14:11 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B2F226B0085; Tue, 25 Jun 2024 18:14:11 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9D1626B008A; Tue, 25 Jun 2024 18:14:11 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 7FE376B0085 for ; Tue, 25 Jun 2024 18:14:11 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id D0B87A1111 for ; Tue, 25 Jun 2024 22:14:10 +0000 (UTC) X-FDA: 82270815060.12.056F1E5 Received: from mail-vs1-f44.google.com (mail-vs1-f44.google.com [209.85.217.44]) by imf23.hostedemail.com (Postfix) with ESMTP id 15929140010 for ; Tue, 25 Jun 2024 22:14:07 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=AOuj1D+e; spf=pass (imf23.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.217.44 as permitted sender) smtp.mailfrom=21cnbao@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1719353632; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=TBmF8qpxGKp1kzaqDCL3gOxUmnHpnL0NKHPV85ofbcw=; b=zswg77O3qZLV25bYS/ZTV5HcgP+JWe6+4dn4SzHtVnL6Yu21UIa2fz9p7Ko6O8ki9fR10Z 204HmNJ7JBAp8sHrmzoo3JyBbgPAx5sI6WWTCUeqrnUpw2ODE+UkXBaIrDyCFrM3JHqxad t+qrY00Y+II2zfop/E1cSgL4dC/DgZE= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1719353632; a=rsa-sha256; cv=none; b=hQ0/vSaxr1ebUndVoFADTXz20oCY+fmOzdLDTmWcuo7ge3mTrCgXDKr2KiwRhMazTg2qro SqpQuuz4D1SS2RC6z3cacEdBQRe3WZuCnh8NUsJn2NvkiYjyFwSfp++1ceY+xEH+a1Jqz1 3cVFK4d62uzD5zPKghWrb5Nd0cd1czA= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=AOuj1D+e; spf=pass (imf23.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.217.44 as permitted sender) smtp.mailfrom=21cnbao@gmail.com; dmarc=pass (policy=none) header.from=gmail.com Received: by mail-vs1-f44.google.com with SMTP id ada2fe7eead31-48f42bfb6c4so1835056137.1 for ; Tue, 25 Jun 2024 15:14:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1719353647; x=1719958447; darn=kvack.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=TBmF8qpxGKp1kzaqDCL3gOxUmnHpnL0NKHPV85ofbcw=; b=AOuj1D+eYKZwoPfgnz1QxYpjFbyt7P+v93kOpoNymhpU6uwU24M9dsULd/jVypSA01 Rf/Ai/MC2mOnqMDHvplV648DML7xPc+BlBiSTNWYR/hirQdLvQWXDKIZGdePxHO/goce +2ZqU+PonfteW0nbxZL/VlM4zqiDxik+YH67z2eJgAIAp4wMKo3rkRwgWEJwuZ9U2Zp2 E/UWyrDgnsnbI8gGqsq6RmO2AIvTUXDrpPKQQcs4RuNTKYm3c1lBG2i3am2L2f8HfOH7 QLt12AHBS2OQlyqA9/c6XU3GMcQkeFrhyYN2MXcj8RDUfxuGfIRIzU+kfUy1r55R0kxu tXHQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719353647; x=1719958447; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=TBmF8qpxGKp1kzaqDCL3gOxUmnHpnL0NKHPV85ofbcw=; b=cH3Uhd8KNu94CnMrFrcEsV/3kV5K2bVBmsSSUFEFTUlrCL6p1ufXolPaq4NhiSGt8W iFBLmuk/uIEDoZS2Lm0UglXieN5d4kg8ks+bVpC9lwACMddkng7WUPQJ4s6SlQ78DmD9 iXRrcz5GyWDfjsb9kKyBv9qXTnAerGDwZtVULpElWOSm9/SGOMrj/3ZoL/xpr50eeXgh YG+9NxFBWJm43163fFHWgQ8CcT1EfhW3ZNUNeq0Xukn0+BET91jBrvb878UvOHfqoWkK ymB3YJW+HryT8onX/zMozTBwyB4S485rqb7RAAMVi8UGGcQsZkZ2kAjNz9jpNmnzmg56 pBkg== X-Forwarded-Encrypted: i=1; AJvYcCUfMr+9PaDEI5kmrjJbSRxIWMwS00QoeKmf0zRcrPPG4QaGaV1QW8rt5fB5KoIddpudpCVlFZxmm3fmNWhKD0kv3WI= X-Gm-Message-State: AOJu0Yxt//c5bdWCmXJxSXurQp9ZApYuB6bJZ9H1Rr0jDgR8/ME0jn3b t1ueC0NdMONbCYoesMfBUR2AR/0Ytj7xyT7u2u8g4uRjo6Y6PQgTkQWy/pEFc5mdxppnBQ/HxOI ez/xWSqMZ3jR0i83pYjyFoMc5vtc= X-Google-Smtp-Source: AGHT+IEe3U160qIaAae3LU0qSN+AdvBf2PQzMdPzqDSRdlUQa+mlog2LEP0qLJUERlyXVjG9VKP+xuiphHVlraBul6g= X-Received: by 2002:a05:6102:11e5:b0:48d:9b0b:903d with SMTP id ada2fe7eead31-48f68ff4cf2mr4849015137.5.1719353647033; Tue, 25 Jun 2024 15:14:07 -0700 (PDT) MIME-Version: 1.0 References: <20240622071231.576056-1-21cnbao@gmail.com> <20240622071231.576056-2-21cnbao@gmail.com> In-Reply-To: From: Barry Song <21cnbao@gmail.com> Date: Wed, 26 Jun 2024 10:13:55 +1200 Message-ID: Subject: Re: [PATCH v2 1/1] tools/mm: Introduce a tool to assess swap entry allocation for thp_swapout To: Kairui Song Cc: akpm@linux-foundation.org, chrisl@kernel.org, linux-mm@kvack.org, ryan.roberts@arm.com, david@redhat.com, hughd@google.com, kaleshsingh@google.com, linux-kernel@vger.kernel.org, v-songbaohua@oppo.com, ying.huang@intel.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Stat-Signature: oanb4sb3k4wtjqa8u1yw1qk7cckc3mih X-Rspamd-Queue-Id: 15929140010 X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1719353647-843196 X-HE-Meta: U2FsdGVkX18OflDGpDJvfRmUpKMaZABnVQrB5qBIaLvqQp6BD9IQQPxU/G+QHO1wS4/KHfOzOYQJCV3gs//pzetGnx34Oql74+JtKTcmaAdUCFLqU6LHNWsYUvIcnyoJQ6HfMg/bhnipPhzh6x/SjEnqKd2ZKy+ck3LXYhkYgVr1x5Rsr/ZzIV5l8uZ8+GqicTCBUyw7Fj7KQVK6TryrqzfAVkVtEsxp8BB4Mh5Z1iaHXYaFXomKUk5r/ph4QZBEQv0XaWqJ0TuXYh+TvCy8o7KteRMUAvbOyS6eoe2ZaMaGvfMffFHgDFTPNFs3kcZOqUHgPEfnFdXPlM5Pw3Qj8P0e7vOCquMoSO807RRg5W9G2dcpMBcVDL3tEcF+YN+k2tTBL1oVQzuNU5hOx4tMyAUJuV1G1LMlCWGDdNVR5fgXqPbqwA5URN+efK/P3ObKK8CF32YS8MtcjQK6/69tnB5I3PWtGvV/1LH+CbrWWzkW00YfBmBDGDR94wlHlJwkq8aADkeFL1U5B1Za7VFU6/4bcCAh5xss9/BJAZJLJJ1jKRc1iQvghvEru52AN+lxmI3xx4J2B42ErI0AbTeSsOHqekktGKr2vZAhGcH3AZT0l/BJDu8a19uh68GdE2XDNTMG+anEY1Yu76G8Xegn72GeLr+9bpG03cZntxTQdkcQ328P2nqcy6URwwtqHEG7gyhCRL4CpstxVw46Dv01OSZdVldb+Qb8dNC4ZXkq5w03FxGrc0F88meCZmPqeMASCheQDyDmyH25nS/B+9aq1V/Oi2XJ7TkHVhOr2w/NNwN+YjZUGmnu4pKZxxbMgUhAW3q8tthceRrEW63cGp5Lzn488qk9ZbWt/vPnb0uYHx2IwV9P606Uh33IoPLP5Z6LtnCKo5WzJJxQKh9hDo4uLsBycTaUM6S2k8IvC19i5+qPCITBvmNtOgh05hrBuPAXukNc3cXu1dAG+kv91KT Rol+xOmB W+5dagskBMvHF9c6LFkMZPCPqtAVsPoleXJAtzLyc96KdGC7bkXbLVtH1iqIDNpg89hib0RTg3nq4sU45CKIMJjnifT28D7jHAoim3rU2jw7/irv9KnbO+bbA/JxOQjhR8K1IPL60byfQUQ7YiK72zbu8oyWlW8jD3yZCFMnDTFeGamI9034OewgxGjc3/iswPq0Zfj5tuBmdo3t7bfYgxyuWQFV3HFXwi2DPaF9nRJ8vX7vwVq5P/Sd/ki1A9k4hLeFCcMgXCTWZCtUoxbsD5cKIUWvRcPGVf91MPsAlDED+2OmXsDz0ThZ9m3tIyQKTBmrnTee8y1v5ndi0YzlGkqtnT1WXr2GZ83JinpZukuEmhfOjwLPJW7O4d4518kjMf3GChzQxh0xn8L4= 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: List-Subscribe: List-Unsubscribe: On Wed, Jun 26, 2024 at 5:22=E2=80=AFAM Kairui Song wrot= e: > > On Sat, Jun 22, 2024 at 3:13=E2=80=AFPM Barry Song <21cnbao@gmail.com> wr= ote: > > > > From: Barry Song > > > > Both Ryan and Chris have been utilizing the small test program to aid > > in debugging and identifying issues with swap entry allocation. While > > a real or intricate workload might be more suitable for assessing the > > correctness and effectiveness of the swap allocation policy, a small > > test program presents a simpler means of understanding the problem and > > initially verifying the improvements being made. > > > > Let's endeavor to integrate it into tools/mm. Although it presently > > only accommodates 64KB and 4KB, I'm optimistic that we can expand > > its capabilities to support multiple sizes and simulate more > > complex systems in the future as required. > > > > Basically, we have > > 1. Use MADV_PAGEPUT for rapid swap-out, putting the swap allocation cod= e > > under high exercise in a short time. > > 2. Use MADV_DONTNEED to simulate the behavior of libc and Java heap in > > freeing memory, as well as for munmap, app exits, or OOM killer scenari= os. > > This ensures new mTHP is always generated, released or swapped out, sim= ilar > > to the behavior on a PC or Android phone where many applications are > > frequently started and terminated. > > 3. Swap in with or without the "-a" option to observe how fragments > > due to swap-in and the incoming swap-in of large folios will impact > > swap-out fallback. > > > > Due to 2, we ensure a certain proportion of mTHP. Similarly, because > > of 3, we maintain a certain proportion of small folios, as we don't > > support large folios swap-in, meaning any swap-in will immediately > > result in small folios. Therefore, with both 2 and 3, we automatically > > achieve a system containing both mTHP and small folios. Additionally, > > 1 provides the ability to continuously swap them out. > > > > We can also use "-s" to add a dedicated small folios memory area. > > > > Signed-off-by: Barry Song > > --- > > tools/mm/Makefile | 2 +- > > tools/mm/thp_swap_allocator_test.c | 233 +++++++++++++++++++++++++++++ > > 2 files changed, 234 insertions(+), 1 deletion(-) > > create mode 100644 tools/mm/thp_swap_allocator_test.c > > > > diff --git a/tools/mm/Makefile b/tools/mm/Makefile > > index 7bb03606b9ea..15791c1c5b28 100644 > > --- a/tools/mm/Makefile > > +++ b/tools/mm/Makefile > > @@ -3,7 +3,7 @@ > > # > > include ../scripts/Makefile.include > > > > -BUILD_TARGETS=3Dpage-types slabinfo page_owner_sort > > +BUILD_TARGETS=3Dpage-types slabinfo page_owner_sort thp_swap_allocator= _test > > INSTALL_TARGETS =3D $(BUILD_TARGETS) thpmaps > > > > LIB_DIR =3D ../lib/api > > diff --git a/tools/mm/thp_swap_allocator_test.c b/tools/mm/thp_swap_all= ocator_test.c > > new file mode 100644 > > index 000000000000..a363bdde55f0 > > --- /dev/null > > +++ b/tools/mm/thp_swap_allocator_test.c > > @@ -0,0 +1,233 @@ > > +// SPDX-License-Identifier: GPL-2.0-or-later > > +/* > > + * thp_swap_allocator_test > > + * > > + * The purpose of this test program is helping check if THP swpout > > + * can correctly get swap slots to swap out as a whole instead of > > + * being split. It randomly releases swap entries through madvise > > + * DONTNEED and swapin/out on two memory areas: a memory area for > > + * 64KB THP and the other area for small folios. The second memory > > + * can be enabled by "-s". > > + * Before running the program, we need to setup a zRAM or similar > > + * swap device by: > > + * echo lzo > /sys/block/zram0/comp_algorithm > > + * echo 64M > /sys/block/zram0/disksize > > + * echo never > /sys/kernel/mm/transparent_hugepage/hugepages-2048kB/= enabled > > + * echo always > /sys/kernel/mm/transparent_hugepage/hugepages-64kB/e= nabled > > + * mkswap /dev/zram0 > > + * swapon /dev/zram0 > > + * The expected result should be 0% anon swpout fallback ratio w/ or > > + * w/o "-s". > > + * > > + * Author(s): Barry Song > > + */ > > + > > +#define _GNU_SOURCE > > +#include > > +#include > > +#include > > +#include > > +#include > > Hi Barry, > > Found a small issue while testing your tool.. for better > compatibility, I think you missed , I'm getting > following error without it (with glibc-headers-2.28-236 on el8 > system): > > thp_swap_allocator_test.c:161:30: error: =E2=80=98MADV_PAGEOUT=E2=80=99 u= ndeclared > (first use in this function); did you mean =E2=80=98MADV_RANDOM=E2=80=99? > madvise(mem1, MEMSIZE_MTHP, MADV_PAGEOUT); > ^~~~~~~~~~~~ > > Other in-tree test tools using this flag also includes . Thanks very much, Kairui. I was using some toolchains on both arm64 and x86, but they didn't complain. I agree mman.h is the correct uapi file for MADV_PAGEOUT. 1 72 arch/alpha/include/uapi/asm/mman.h <> #define MADV_PAGEOUT 21 2 99 arch/mips/include/uapi/asm/mman.h <> #define MADV_PAGEOUT 21 3 66 arch/parisc/include/uapi/asm/mman.h <> #define MADV_PAGEOUT 21 4 107 arch/xtensa/include/uapi/asm/mman.h <> #define MADV_PAGEOUT 21 5 73 include/uapi/asm-generic/mman-common.h <> #define MADV_PAGEOUT 21