Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp1653905pxa; Thu, 20 Aug 2020 17:30:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxFJAMsfiL921Nv4xwJEdo7oOBw6JkJ8CN2okryVDw2/t5RcgAzgIpHpqDEai0WW0GB/MLT X-Received: by 2002:a17:906:4f8c:: with SMTP id o12mr474552eju.69.1597969829478; Thu, 20 Aug 2020 17:30:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597969829; cv=none; d=google.com; s=arc-20160816; b=PoE7frfCW9ucdsCa65lr6177TyilL34tPsgr3wmZYlzW/9h2A32SxMiCrk3bSULWem c7c1xpja9o/qaGeqGWkeGop37sedH83LVsAsycmVKss/ZmMkfBm7FwG3VIUxek3B1/yw FzfDEJYMHW1UIRrmCzb1Ks17PvXPWyxo1t+tkeuD52nGYvzh2Wt2jHp6rh6c7Q4vPkFr RGPp+tCItjt8z5lAM64sU/m7SerGqHzpXdaHY9/hykn9GquEPOdAQK2pxwEHHxoQBiS2 I6x1khOHyvcd91ZZKh3m6HGDf57ucYF5J7uQhCgKlNPpA1M14mFf7i6TG3+LaatogX29 Wt7Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=L3JIlPvsMRwkM1mgCcR4mBSnOH7ubXhXyleqb1KzD8U=; b=WHAsvJQFQbYYZy9E8FijDi65JOjqBZy8VHwPBFvZhD085M11Ks7olAd3fIzyL+w3zi 06q7o0WoT8BhkraPbTvSVFr9l9rMSfIwkDDLR/ZkRZFBSTGkOWdK7e6Qlcc1YkDe2JxE bz7uGW7lH/5QcQkbmIs5o/L9LaXXXxSj8oZuunEYv3DmzsNPkGmkiG9UcIOEP/ZdN1kg SGUPxTCuEpKw/YLb3vWNC+qUFotdYZJw8AvLoNZeJRQ+NekbvM3L3foJbXipDUmnQWvs xZvyHd3X10z861hSr9zc87e7c9kWmPAi554vKcSifNrkMBZ5UVfqWwXuP7t8N9Afm3Xx yZvw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=hzi2czJb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ov24si67005ejb.229.2020.08.20.17.30.06; Thu, 20 Aug 2020 17:30:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=hzi2czJb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727069AbgHUA2d (ORCPT + 99 others); Thu, 20 Aug 2020 20:28:33 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:53839 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727031AbgHUA20 (ORCPT ); Thu, 20 Aug 2020 20:28:26 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1597969704; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=L3JIlPvsMRwkM1mgCcR4mBSnOH7ubXhXyleqb1KzD8U=; b=hzi2czJb/h7wsN3T9CCJrMYXiByc1oVK7P3bAU5mcwCCi0D1C1gQUc5vYN1zb0qYJuAGLJ p2cZ35p2jTLsMRi4ph309hgKcQKiK4jpNRLLZsnEa7CpIg1U2qP7pBOHFOFCPQMgv1iVEI EPSF3EHG9OwS6kEBG6HJ36fFZ61oaTs= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-563-e07Wxl8qNreqFdkVdHJf3g-1; Thu, 20 Aug 2020 20:28:23 -0400 X-MC-Unique: e07Wxl8qNreqFdkVdHJf3g-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C95BA1074649; Fri, 21 Aug 2020 00:28:21 +0000 (UTC) Received: from optiplex-lnx (unknown [10.3.128.5]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4ED4A10098A7; Fri, 21 Aug 2020 00:28:12 +0000 (UTC) Date: Thu, 20 Aug 2020 20:28:10 -0400 From: Rafael Aquini To: Dave Chinner Cc: Gao Xiang , Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Carlos Maiolino , Eric Sandeen , "Huang, Ying" , Yang Shi , stable Subject: Re: [PATCH v2] mm, THP, swap: fix allocating cluster for swapfile by mistake Message-ID: <20200821002810.GA3096383@optiplex-lnx> References: <20200820045323.7809-1-hsiangkao@redhat.com> <20200820233446.GB7728@dread.disaster.area> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200820233446.GB7728@dread.disaster.area> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Aug 21, 2020 at 09:34:46AM +1000, Dave Chinner wrote: > On Thu, Aug 20, 2020 at 12:53:23PM +0800, Gao Xiang wrote: > > SWP_FS is used to make swap_{read,write}page() go through > > the filesystem, and it's only used for swap files over > > NFS. So, !SWP_FS means non NFS for now, it could be either > > file backed or device backed. Something similar goes with > > legacy SWP_FILE. > > > > So in order to achieve the goal of the original patch, > > SWP_BLKDEV should be used instead. > > > > FS corruption can be observed with SSD device + XFS + > > fragmented swapfile due to CONFIG_THP_SWAP=y. > > > > I reproduced the issue with the following details: > > > > Environment: > > QEMU + upstream kernel + buildroot + NVMe (2 GB) > > > > Kernel config: > > CONFIG_BLK_DEV_NVME=y > > CONFIG_THP_SWAP=y > > Ok, so at it's core this is a swap file extent versus THP swap > cluster alignment issue? > > > diff --git a/mm/swapfile.c b/mm/swapfile.c > > index 6c26916e95fd..2937daf3ca02 100644 > > --- a/mm/swapfile.c > > +++ b/mm/swapfile.c > > @@ -1074,7 +1074,7 @@ int get_swap_pages(int n_goal, swp_entry_t swp_entries[], int entry_size) > > goto nextsi; > > } > > if (size == SWAPFILE_CLUSTER) { > > - if (!(si->flags & SWP_FS)) > > + if (si->flags & SWP_BLKDEV) > > n_ret = swap_alloc_cluster(si, swp_entries); > > } else > > n_ret = scan_swap_map_slots(si, SWAP_HAS_CACHE, > > IOWs, if you don't make this change, does the corruption problem go > away if you align swap extents in iomap_swapfile_add_extent() to > (SWAPFILE_CLUSTER * PAGE_SIZE) instead of just PAGE_SIZE? > I suspect that will have to come with the 3rd, and final, part of the THP_SWAP work Intel is doing. Right now, basically, all that's accomplished is deferring the THP split step when swapping out, so this change is what we need to avoid stomping outside the file extent boundaries. > I.e. if the swapfile extents are aligned correctly to huge page swap > cluster size and alignment, does the swap clustering optimisations > for swapping THP pages work correctly? And, if so, is there any > performance benefit we get from enabling proper THP swap clustering > on swapfiles? > > Cheers, > > Dave. > -- > Dave Chinner > david@fromorbit.com >