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 7D53EC2BD09 for ; Mon, 24 Jun 2024 07:01:09 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 887E06B0429; Mon, 24 Jun 2024 03:01:08 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8383C6B042A; Mon, 24 Jun 2024 03:01:08 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6B27D6B042B; Mon, 24 Jun 2024 03:01:08 -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 49C556B0429 for ; Mon, 24 Jun 2024 03:01:08 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id D8F2B140B6B for ; Mon, 24 Jun 2024 07:01:07 +0000 (UTC) X-FDA: 82264885374.12.FBDA722 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.18]) by imf04.hostedemail.com (Postfix) with ESMTP id 0848440026 for ; Mon, 24 Jun 2024 07:01:04 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=PflCoFbA; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf04.hostedemail.com: domain of ying.huang@intel.com designates 192.198.163.18 as permitted sender) smtp.mailfrom=ying.huang@intel.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1719212451; 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=Lx+VLAGsi/WCpjQn+3HfyUUUUOnTdOrSWVO7SIpM1dQ=; b=GAfepQV4aWicGCyAxiYCQZz3H+BxYVhgU1bsqrH4RgpU57BOcxvDvBVvR7sisG9+ZkybwI hxFmEdTLTlOeU4pWyHBORcncO2ck2WeVWKWDPQwoON4pMpcR7Hn5nJ9PVBnE6AU1d0u28S 15orJyak4BuTEXBXblsJdGw1K0WvPgo= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1719212451; a=rsa-sha256; cv=none; b=OOv2pwrvIsTmzYHvzpDQFjHWFqVDZugvuxN0QJD4U5/6vpyeR4Y+j9UndUCgmoUzIj37UQ OCdlWrMAj0wsvwcKjmLpwpyBsJGd9ZVRp/qN3Nhp0H3QKQHc0WII+NDsQCFWAIWncpO4U0 3FnTGBLeSwsWMNhh3mmnSgWQlRe5tvQ= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=PflCoFbA; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf04.hostedemail.com: domain of ying.huang@intel.com designates 192.198.163.18 as permitted sender) smtp.mailfrom=ying.huang@intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1719212465; x=1750748465; h=from:to:cc:subject:in-reply-to:references:date: message-id:mime-version:content-transfer-encoding; bh=vysncUCoKhlu8IYF+ovoiOg/W8vMI8Njteu+rthszIg=; b=PflCoFbAKOQ1wZyPVWA8pt1gS1JSNSQ2mfUCR0SZ5s9hk785CsEMaled HsG7FlpEj0HhqyM75GmWIV45MqK22ILmM/QWK12J9/7EoX86nIYUiSUdo 3D8yQsE6aMYioFA/DvhEjakBPPAXJxA2Sg+Zof5KGXmMXyzK3MzA0aiSz zMzdTVZpUF1eZnvEPiLnNy9wzlprrGJxn2+90yKxG0z+P007m2XiFBhNO AxAtnc+zJxBHexzSJ2xuDM0yGeJCRP0kIxPGbnZy4coMxt0fjm+OKDn+O yO/UogL4qMZ19OncEPpGSfUn76DiJzZBGeF3xjj5ayV/IipeK2Z3MKHVH A==; X-CSE-ConnectionGUID: 09vSfRMeSGSpKkjtImu4hA== X-CSE-MsgGUID: hQ4xP+7ERBeqqmrkwFyxQA== X-IronPort-AV: E=McAfee;i="6700,10204,11112"; a="15859103" X-IronPort-AV: E=Sophos;i="6.08,261,1712646000"; d="scan'208";a="15859103" Received: from fmviesa005.fm.intel.com ([10.60.135.145]) by fmvoesa112.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Jun 2024 00:01:03 -0700 X-CSE-ConnectionGUID: 2G9ck0J0QrKUee6WV/mE4Q== X-CSE-MsgGUID: SaZ8xHkJRCS25xxymusKGQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,261,1712646000"; d="scan'208";a="47652596" Received: from unknown (HELO yhuang6-desk2.ccr.corp.intel.com) ([10.238.208.55]) by fmviesa005-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Jun 2024 00:01:00 -0700 From: "Huang, Ying" To: Barry Song <21cnbao@gmail.com> Cc: Ryan Roberts , David Hildenbrand , akpm@linux-foundation.org, shuah@kernel.org, linux-mm@kvack.org, chrisl@kernel.org, hughd@google.com, kaleshsingh@google.com, kasong@tencent.com, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, Barry Song Subject: Re: [PATCH] selftests/mm: Introduce a test program to assess swap entry allocation for thp_swapout In-Reply-To: (Barry Song's message of "Mon, 24 Jun 2024 16:05:44 +1200") References: <20240620002648.75204-1-21cnbao@gmail.com> <87cyoa1wgm.fsf@yhuang6-desk2.ccr.corp.intel.com> <878qyv0zwk.fsf@yhuang6-desk2.ccr.corp.intel.com> Date: Mon, 24 Jun 2024 14:59:09 +0800 Message-ID: <871q4m25du.fsf@yhuang6-desk2.ccr.corp.intel.com> User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 0848440026 X-Stat-Signature: yzgii9cgi7e71pw5ouybfr56isdniba9 X-Rspam-User: X-HE-Tag: 1719212464-361852 X-HE-Meta: U2FsdGVkX19uaQ89zflk02qStMttZdtoP4gC5F/Ft1m3YLZ6H3fhlSTME4Ge4vlVtkLvUdOQ1JH15lzDbTP29Nbkp3HQOSx/8+o9ccIub84GM4CbbpWbD0bqv1mvAXlIn/Gwxzq2SAtKGg+SP+EcAZNXkGfzCwCWXPgpsBQdSDYqo8V2vdGyEvQ5qT1U/zS6jYEvBQOvID8JIjyWozrWmqQCrJrGGZXAMmYxq/3Ouc8kfNoaNP6JFxWt9MMhS9TLOzLSeeOQzL0huYKETais14TmXC6JQwy3kLSff8aghUXWRz/SC709RkRwey3VgGxq1DBNlq0OTyYTMyBl0lXwWPKcEFvaVljNL2jTnFccjSqcSp8adB46+2PCJ/Mc53dWMAOL9nzKLzYjW0RWy12mkfMTUPenPOKBvfOtANeojezB9EM1MaqwJmkPYMmr7LoeqLiiH7mdf1c0qg2LCQt9HBx4oC2Kqv/qwKC4DPMxwN9TsSb47mrfVns0kdzIcWrlseVwzTSV8+rFEEcOnxbX2rIK8nHui/M7ky1ct/JXJxVgzF63Lqew9ZrRuyBGRcuIJjeJkIXBiVDK0zLDp6Kr3M/jlbgeYpHOE8Vw60eiQIxd69xXWSssAobPIU6DPVPXwz/GaSuJ0GNgS19veqq9eH6lKyWkHM5+Y6L8R+60ytLEohKsabfYNTPhHbNDOXhNCNv8rBM8jHYT7+/MKyZGYPj9mZezIHvt23q/egLgiW5xevsfJBccTTLLCInVC4JZRVFxOCUQGU/5iWzmdikBH3MIpA9HOIlytG8Zu2Vt43yV5gCjcoLuTM+s+IfE3X83vXCoQkFW5532xs0GkcKQ/cE7beBZHcgpT7OXeOsAS281WWteOePraX+wdzhGKT0PC1wvWjT59wqAuVVeSJ0DmElOXyHJH9N/3hW+V1V4i/LmYwh13ijjmMhsHXIN0xl0hLv3qLc4jt4UZwbGPri CgNsk8Xj 6a2bZ4gefKF87eZoIW9m3ZI3MggFJCmxqHp4kShv4d7sokgMAXH+MzDoCbKDf4LOoKynm85HrkLnYBJxxyO9h4WJKtB9SM+I2PtTX1GBOUKnTKUYMHuib+QVrTCVTwpyaEAGrTRrHx+8CqrjKv0oyhTinKpeB+t1/jdWk62BiajHvDzRvuZQi15HQJ3luNLl3YZZfzO57X9JE+p76jQk54ocIEaRvlwQKWaxe9Kj3RTSqPbzT9x1mdJEFEzl/m0RiwVoplZOwzbWXuBxWMpw4GlucljI6OKiakIKdbNEPSF5gGCO08fOuYBNMUW/lmmah3tdcJHNjsP5k7vaYfv8Gw0E+fVMxEtvBLNqMXQel+mSYFFU= 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: Barry Song <21cnbao@gmail.com> writes: > On Mon, Jun 24, 2024 at 3:44=E2=80=AFPM Huang, Ying wrote: >> >> Barry Song <21cnbao@gmail.com> writes: >> >> > On Fri, Jun 21, 2024 at 9:24=E2=80=AFPM Huang, Ying wrote: >> >> >> >> Barry Song <21cnbao@gmail.com> writes: >> >> >> >> > On Fri, Jun 21, 2024 at 7:25=E2=80=AFPM Ryan Roberts wrote: >> >> >> >> >> >> On 20/06/2024 12:34, David Hildenbrand wrote: >> >> >> > On 20.06.24 11:04, Ryan Roberts wrote: >> >> >> >> On 20/06/2024 01:26, Barry Song wrote: >> >> >> >>> 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 assess= ing the >> >> >> >>> correctness and effectiveness of the swap allocation policy, a= small >> >> >> >>> test program presents a simpler means of understanding the pro= blem and >> >> >> >>> initially verifying the improvements being made. >> >> >> >>> >> >> >> >>> Let's endeavor to integrate it into the self-test suite. Altho= ugh 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. >> >> >> >> >> >> >> >> I'll try to summarize the thread with Huang Ying by suggesting = this test program >> >> >> >> is "neccessary but not sufficient" to exhaustively test the mTH= P swap-out path. >> >> >> >> I've certainly found it useful and think it would be a valuable= addition to the >> >> >> >> tree. >> >> >> >> >> >> >> >> That said, I'm not convinced it is a selftest; IMO a selftest s= hould provide a >> >> >> >> clear pass/fail result against some criteria and must be able t= o be run >> >> >> >> automatically by (e.g.) a CI system. >> >> >> > >> >> >> > Likely we should then consider moving other such performance-rel= ated thingies >> >> >> > out of the selftests? >> >> >> >> >> >> Yes, that would get my vote. But of the 4 tests you mentioned that= use >> >> >> clock_gettime(), it looks like transhuge-stress is the only one th= at doesn't >> >> >> have a pass/fail result, so is probably the only candidate for mov= ing. >> >> >> >> >> >> The others either use the times as a timeout and determines failur= e if the >> >> >> action didn't occur within the timeout (e.g. ksm_tests.c) or use i= t to add some >> >> >> supplemental performance information to an otherwise functionality= -oriented test. >> >> > >> >> > Thank you very much, Ryan. I think you've found a better home for t= his >> >> > tool . I will >> >> > send v2, relocating it to tools/mm and adding a function to swap in >> >> > either the whole >> >> > mTHPs or a portion of mTHPs by "-a"(aligned swapin). >> >> > >> >> > So basically, we will 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, similar to t= he behavior >> >> > on a PC or Android phone where many applications are frequently sta= rted and >> >> > terminated. >> >> >> >> MADV_DONTNEED 64KB memory, then memset() it, this just simulates the >> >> large folio swap-in exactly, which hasn't been merged by upstream. I >> >> don't think that it's a good idea to make such kind of trick. >> > >> > I disagree. This is how userspace heaps can manage memory >> > deallocation. >> >> Sorry, I don't understand how. Can you show some examples? Such as >> strace log with 64KB aligned MADV_DONTNEED? > > In Java heap and memory allocators such as jemalloc and Scudo, memory is = freed > using the MADV_DONTNEED flag when either free() is called or garbage coll= ection > occurs. In Android, the Java heap is freed in chunks aligned to 64KB > or larger. Originally, I heard about that MADV_FREE is used by jemalloc. Now, I know that they use MADV_DONTNEED too. Thanks! Although I still suspect that libc/java allocator will free pages in exact 64KB size (IIUC, they should free pages in much larger trunk). I agree that MADV_DONTNEED is a way to create fragmentation in swap devices. > In > Scudo and jemalloc, there is a configuration option to set the > management granularity. > This granularity is set to match the mTHP size(though the default > value is 16KB in the > latest Android if we don't run mTHP). Otherwise, you could end up with > millions of > partial unmap operations, which would severely degrade the performance of= mTHP. > > Imagine libc/Java functioning like a slab allocator. When kfree() is > called, some pages > may become completely unoccupied and can be returned to the buddy allocat= or. In > userspace, memory is given back to the kernel in a similar manner, > typically using > MADV_DONTNEED. Therefore, MADV_DONTNEED is the most common memory > reclamation behavior in Android, coming with free(), delete() or GC. > > Imagine a system with extensive malloc, free, new, and delete > operations, where objects > are constantly being created and destroyed. > > On the other hand, whether libc/Java use MADV_DONTNEED to free memory is = not > crucial, although they do. We need a method to simulate the lifecycle > of applications > =E2=80=94exiting and starting anew=E2=80=94on PCs or Android phones. It d= oesn't matter if you > use MADV_DONTNEED or munmap to achieve this. > > It is important to note that mTHP currently operates on a one-shot > basis(after swap-out, > you never get them back as mTHP as we don't support large folios > swapin). For the test > program, we need a method to generate new mTHPs continuously. Without thi= s, > after the initial iterations, we would be left with only folios, > rendering the entire > test program *pointless*. I understand the requirements for new mTHPs. >> >> > Additionally, in the event of an application exit, munmap, or OOM kill= er, the >> > amount of freed memory can be much larger than 64KB. The primary purpo= se >> > of using MADV_DONTNEED is to release anonymous memory and generate >> > new mTHP so that the iteration can continue. Otherwise, the test progr= am >> > becomes entirely pointless, as we only have large folios at the beginn= ing. >> > That is exactly why Chris has failed to find his bugs by using other s= mall >> > programs. >> >> Although I still don't understand how 64KB aligned MADV_DONTNEED is used >> for libc/java heap or munmap in a practical way. After more thoughts, I >> think 64KB Aligned MADV_DONTNEED can simulate the fragmentation effect >> of processes exit at some degree if 64KB folios in these processes are >> swapped out without splitting. If you have no other practical use >> cases, I suggest to make it explicit with comments in program. >> [snip] -- Best Regards, Huang, Ying