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 CB60CC761A6 for ; Thu, 6 Apr 2023 12:55:23 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E52B56B0071; Thu, 6 Apr 2023 08:55:22 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E037B6B0074; Thu, 6 Apr 2023 08:55:22 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CF3146B0075; Thu, 6 Apr 2023 08:55:22 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id C0AF06B0071 for ; Thu, 6 Apr 2023 08:55:22 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 92E8D1612E2 for ; Thu, 6 Apr 2023 12:55:22 +0000 (UTC) X-FDA: 80650962084.16.FD311F1 Received: from out30-100.freemail.mail.aliyun.com (out30-100.freemail.mail.aliyun.com [115.124.30.100]) by imf30.hostedemail.com (Postfix) with ESMTP id A74048001B for ; Thu, 6 Apr 2023 12:55:18 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=alibaba.com; spf=pass (imf30.hostedemail.com: domain of rongwei.wang@linux.alibaba.com designates 115.124.30.100 as permitted sender) smtp.mailfrom=rongwei.wang@linux.alibaba.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1680785720; 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; bh=NHi7qKxJ872jO3e3yh9O9fkOuJd6PxvHc2oxPm3Hh9Y=; b=yCp/hr5fUn2JrFIe2cY6eqSL0DZB5KP3pLdAIEaAkCowEoAvjxSrFwM4CwvnQGIYBZEnJH jtfcIxyp2o6YcUx0fsL8IHEB4qXkkUl0t++spTapTfG+1yfTzYDEmdxYk4h43zDkqpBvQm nUP1Sn6EINvliMTXDRSHmzeCkyHIJbM= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=alibaba.com; spf=pass (imf30.hostedemail.com: domain of rongwei.wang@linux.alibaba.com designates 115.124.30.100 as permitted sender) smtp.mailfrom=rongwei.wang@linux.alibaba.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1680785720; a=rsa-sha256; cv=none; b=Tj10g7z4z3EHQHltS8RGBBVa+iWLB4U0Nd3e1oSfaZJ5whvfqBYK39kysiH4DWO6ZLTKKy NlCsuG+o8HrRH/y+1rfYn2kqtvFAsHxKXByMM7LpeykEd5JgDu7zFIYkQUmu1iMNvs+nrC r7KjugJGjJHLnzUgyzd7IWx2jY4J9js= X-Alimail-AntiSpam:AC=PASS;BC=-1|-1;BR=01201311R101e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018046050;MF=rongwei.wang@linux.alibaba.com;NM=1;PH=DS;RN=7;SR=0;TI=SMTPD_---0VfTAMRc_1680785713; Received: from 30.221.129.255(mailfrom:rongwei.wang@linux.alibaba.com fp:SMTPD_---0VfTAMRc_1680785713) by smtp.aliyun-inc.com; Thu, 06 Apr 2023 20:55:14 +0800 Message-ID: Date: Thu, 6 Apr 2023 20:55:12 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.9.1 Subject: Re: [PATCH v2] mm/swap: fix swap_info_struct race between swapoff and get_swap_pages() Content-Language: en-US To: Aaron Lu Cc: akpm@linux-foundation.org, bagasdotme@gmail.com, willy@infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org References: <20230401221920.57986-1-rongwei.wang@linux.alibaba.com> <20230404154716.23058-1-rongwei.wang@linux.alibaba.com> <6dad8c2f-b896-3cc0-26c1-37f5fff406bd@linux.alibaba.com> <20230406121245.GA376058@ziqianlu-desk2> From: Rongwei Wang In-Reply-To: <20230406121245.GA376058@ziqianlu-desk2> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Rspam-User: X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: A74048001B X-Stat-Signature: h9q74feddig8751yb494eaw67c6o88tr X-HE-Tag: 1680785718-605585 X-HE-Meta: U2FsdGVkX18Y1yDM2+BlSdHLGJSeBjzvDx3eOYzvqSxNnw77NsZHcutav2nKhgS8SWktioEU7DHO7lDiTL4vDt2ZIo1vrOlnfUI/Pz9QU1gIdxd+wJl0lxYfWGVbCDR9DfDjB303EW2Y6KBj5bpMIScpRsjavlxBIEM+3VxDVRb4JbSOcKt4omV7hXuIQLc5Sh0/T811JrjFRkBPOAPhB/UnaF6GiD39XeXyJK36ZvnV34d4WgZid7DQHh5GnH76UtbNM7HqHKqbpALg+uWzwjok5ekLsIz2DUkl/Q6ODS/+M6kQoWHicZuEHD4dcE0Mh6K5YSyz7C4CyJM9Ncei7iMWTdf9isRD7l6RZUPOxxtymrsxyziGFYmH9aBCjLAKjoahV82ZBZ0xO/fLxzTgL+k/u/csUe7X9CMrnwASiALFVCUsWsnyHBoUYCZLujEaJWNCGd9KVEGMvL9QF8tIOkQdubauSVKmicNpvlcYD+95OQSkjKHCu4d5D7qyKRm5NSQca+oLbXrrqDHlqj93/LVmuWkWii5e3MVATRMLQNpcnEmWytLNiSBXLbqlaCrlCvvhNoQR/RqYeUqU5Jcelhwy0zTi3GMAXsk5FEMeppDNGcEubvZa295U76vK5Pl/BPqq8vtiZNVgHv6nHDlPXo/icRc3XddfsQvoAwU8qqDk9hHnCjhHp/WuqpUIXvjs/qjPHSn9+w4sw9EC9GnLaKIqVN4UqIw3qsUum0iI/ZxixC3an4nNefbhhCV1kDgtKc6pAHr+zgxqp23cMCX1RmgKSKCkvdtWZt4dRicYOuD60g4a7Zec1nMABA53+Lu/SYDNmdABK91qGOnR3FAVYK6e/ccYQ5iYrPfClMd0mk8KAqECCem0e5K6tJh2H8xqB5NqSS/anSfFo4NJrfL7sbp0ZsEs3O0Ycucsr+BrGyqoJPQBsoMgpb9l5hLrvMT1DAW03yjmpJcfi8J9OZ6 TYUfbzi9 B6ythcnx64qwrCB79So5HjpBzgnb/3HRYD0LUD7MFq01DQ1JrUR6wCVv1YHOibqMVqjgonVra7szAE5lGKUre3hMPkDfpKrpYVwRYi6W7EHacK998qiscM9+WEwSBqijFVGG2d9fV1v023xcUzGswitD6Rg== 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: Oh, sorry, I miss this email just now, that because of I'm also replying your previous email. On 2023/4/6 20:12, Aaron Lu wrote: > On Wed, Apr 05, 2023 at 12:08:47AM +0800, Rongwei Wang wrote: >> Hello >> >> I have fix up some stuff base on Patch v1. And in order to help all readers >> and reviewers to >> >> reproduce this bug, share a reproducer here: > I reproduced this problem under a VM this way: > > $ sudo ./stress-ng --swap 1 > // on another terminal > $ for i in `seq 8`; do ./swap & done > Looks simpler than yours :-) Cool, indeed become simpler. > (Didn't realize you have posted your reproducer here since I'm not CCed > and just found it after invented mine) > Then the warning message normally appear within a few seconds. > > Here is the code for the above swap prog: > > #include > #include > #include > > #define SIZE 0x100000 > > int main(void) > { > int i, ret; > void *p; > > p = mmap(NULL, SIZE, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, 0); > if (p == MAP_FAILED) { > perror("mmap"); > return -1; > } > > ret = 0; > while (1) { > for (i = 0; i < SIZE; i += 0x1000) > ((char *)p)[i] = 1; > ret = madvise(p, SIZE, MADV_PAGEOUT); > if (ret != 0) { > perror("madvise"); > break; > } > } > > return ret; > } > > Unfortunately, this test prog did not work on kernels before v5.4 because > MADV_PAGEOUT is introduced in v5.4. I tested on v5.4 and the problem is > also there. Maybe that is this bug can not be found since now. And we found this is triggered by stress-ng-swap and stress-ng-madvise (PAGEOUT) firstly. It seems this is that reason. It seems MADV_COLD is also introduced together with MADV_PAGEOUT. I have no idea and have to depend on you.:-) > > Haven't found a way to trigger swap with swap device come and go on > kernels before v5.4; tried putting the test prog in a memcg with memory > limit but then the prog is easily killed due to nowhere to swap out. > Personally, I do not intend to continuing searching for the method to reproduce before v5.4. Of course, if you have idea, I can try. Thanks:-)