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 2C714C2BBCA for ; Tue, 25 Jun 2024 17:22:39 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AA9316B0096; Tue, 25 Jun 2024 13:22:38 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A58126B0098; Tue, 25 Jun 2024 13:22:38 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8AAB26B0099; Tue, 25 Jun 2024 13:22:38 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 6B6496B0096 for ; Tue, 25 Jun 2024 13:22:38 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 1D42F1A0436 for ; Tue, 25 Jun 2024 17:22:38 +0000 (UTC) X-FDA: 82270080396.10.45C0A90 Received: from mail-lj1-f181.google.com (mail-lj1-f181.google.com [209.85.208.181]) by imf16.hostedemail.com (Postfix) with ESMTP id 3B942180011 for ; Tue, 25 Jun 2024 17:22:35 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=CkbL5n2W; spf=pass (imf16.hostedemail.com: domain of ryncsn@gmail.com designates 209.85.208.181 as permitted sender) smtp.mailfrom=ryncsn@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1719336148; a=rsa-sha256; cv=none; b=Nk9T1PTrWlItH3ZncZbHOhXkWnzPsDAAYepd1HaXuqFuTJvnS15+k+m4CIqxnPsjdkcBLZ mKgjvREUrZOZW0y++6j91s3znzbyQKKu/WlCDQuZJZzw3HkjL8lroTL2wvQXC5XKUmS2h/ MyjFuYYGxAC+qS4HD5tUH2MMMYRBH/Y= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=CkbL5n2W; spf=pass (imf16.hostedemail.com: domain of ryncsn@gmail.com designates 209.85.208.181 as permitted sender) smtp.mailfrom=ryncsn@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=1719336148; 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=U8+vxqtoku9WMxCA6PXoqwBfKDqGzEMaoj9vVLQWGmg=; b=Obyzn7JRxBnPldzB3jrvlateu6pYIDf4EaN/11fdFSYjtr2iypLDb57g9UxwAHwDBCU6/e H8FgdYb3AAs2JyxmMuBrWSfboVoozTVkm20Jomkbt0vh5JPmTj9Cwd07utqYcHe+VkiVDE N47SxyZPXwqfnjSQrLeouxfs4M5pwvA= Received: by mail-lj1-f181.google.com with SMTP id 38308e7fff4ca-2ec6635aa43so19334511fa.1 for ; Tue, 25 Jun 2024 10:22:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1719336155; x=1719940955; 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=U8+vxqtoku9WMxCA6PXoqwBfKDqGzEMaoj9vVLQWGmg=; b=CkbL5n2WdhJzknaWTORuVnMtgyL7k/aN1VX3GGYI0SU4giYCwI91Clgx4/zfhWijKx 6JrUFa/A9isIbRzQe+ShJZ8lsGpFwcZwuC1UXZAPyMPCcETbF4lnm0Vszyj7OFWmg5GW Of9hCA6IPEOk5Bz52rwMYiXDCMsA4oWrBRZyMpod6yu+i1ykyzxux0hiVnlNowc4xfzk J1ySHQ6gQRTNX140D94IqhokvirAKWbqfZw9IUBtgihfarGhaM5DPxhU/Cufm0Y5Nku0 RjbqQw9hlFyVzNHTr4BK+5Y/TmKDg83nh16G//mndqGWymgBrAP2n0fmuAdbe3EGFuZK t8dA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1719336155; x=1719940955; 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=U8+vxqtoku9WMxCA6PXoqwBfKDqGzEMaoj9vVLQWGmg=; b=DykP4n7aLkQT4pUQitVlFdBCxx35JCXFdf1C28w2Vx7RIy/cuqdwgU2hWVfRB5+uNM 9l+Uq9LWZbJcZRMTOXSjjY1jSzvcBRPRzeqLs/HkyPs5BGO9wQdEYVCDnRrKGlFKYcea n+nxGynO0iXQryNOlEJgy85FC+I8pRcZD6gtEoDVeA643J+YZns+DnP3pbcnag06YEq/ DDiaPItmaWsNA3LCThsJDvg8kRufwLhHWrvzQkVLeHG7Hx0ytoFo8wwBrN+RW8+xDgM9 em0k7v2tHWTpsGuISgPNEF2Y/p7Fpp6UlT58xabx1JbBn7danJb2/zqfGKzpx6eogjtv 7IOg== X-Forwarded-Encrypted: i=1; AJvYcCVNDJOWvOhpYhclTKGsIZRs5goYIQPXZGHPo/GaeWteh+ssgDRjui96S+dLhDkkF9nmqzdfKaPGWUAYYCyCQeWgBXU= X-Gm-Message-State: AOJu0YxAMtfzOVSYY6qp9aEMwZqWpmUYZcWuhlAve2bXwRm5Gk6x+gmP wj/N+jRS8ikUflKuoeZ5FaiR3XxlVvx8XkD4lLLJ0iFkNYLl/JULH88aBnp0zSTtTDZ2uGo1T9+ o28Hfon8f2pntgOKvg2uBHDHLoDU= X-Google-Smtp-Source: AGHT+IENflu0IhOwnz3G7CoO5qIYDSrf3yQTxo4pN2s8oFrddW68LdZ70xyM8SUrG1NNxvukXAkxa3vCptR2WVA9VfU= X-Received: by 2002:a05:651c:b0d:b0:2ec:5f0d:8b08 with SMTP id 38308e7fff4ca-2ec5f0d8f83mr62208701fa.37.1719336154320; Tue, 25 Jun 2024 10:22:34 -0700 (PDT) MIME-Version: 1.0 References: <20240622071231.576056-1-21cnbao@gmail.com> <20240622071231.576056-2-21cnbao@gmail.com> In-Reply-To: <20240622071231.576056-2-21cnbao@gmail.com> From: Kairui Song Date: Wed, 26 Jun 2024 01:22:17 +0800 Message-ID: Subject: Re: [PATCH v2 1/1] tools/mm: Introduce a tool to assess swap entry allocation for thp_swapout To: Barry Song <21cnbao@gmail.com> 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: hkqic4oeymn8dasy97bx19wdyoi9k66c X-Rspamd-Queue-Id: 3B942180011 X-Rspam-User: X-Rspamd-Server: rspam10 X-HE-Tag: 1719336155-82695 X-HE-Meta: U2FsdGVkX19d1Jh2eWMhldTO5+k+TVvhHo8y2wWD8ygf9fVGz1O0kepEIQjwrJwd3FbMNv6K5V/2Xx8WTzrJGTDVaOj5Wd/RR2T6WyCieTGiE5PJAjaJgOVCBQfFINhe5A1AIoCdd0MXXVIXNkrc6r1tFjNpChysayhQejcpGXK+4D3cMnLEsLp0T+teosNRpDmRZjsNQ7c8ukF9w+g+x27uDRlFSNtOjwFMJiCefa2XM+4DGzMH9/Gcvu6o9AVuK9Za3/x1ZjHxadLvoNgzdAm4E64yfJnpt3lZMwL2OxEXl1heleztcRtWjaTZ9nLbM5lSRqRxfHJUvBs9+WuP7R28cULCGzqoa0vfDB6ipWw3f6kV3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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 Sat, Jun 22, 2024 at 3:13=E2=80=AFPM Barry Song <21cnbao@gmail.com> wrot= e: > > 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 code > 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 scenarios= . > This ensures new mTHP is always generated, released or swapped out, simil= ar > 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_t= est > 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_alloc= ator_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/en= abled > + * echo always > /sys/kernel/mm/transparent_hugepage/hugepages-64kB/ena= bled > + * 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 und= eclared (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 .