Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp1046130ybk; Wed, 20 May 2020 19:55:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz0Cyw2LwEwOtfd26k1M18GJElSoyqTv3ErVqeoq+BOzg5Mp+XWPibuGCwqvpkIg8O/Y4hS X-Received: by 2002:a17:906:b4e:: with SMTP id v14mr1687597ejg.302.1590029713601; Wed, 20 May 2020 19:55:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590029713; cv=none; d=google.com; s=arc-20160816; b=mSN46tI7krll7ygcqko7FpQgKc+GCFWWCiemvB2iGvpYcIQSG8hcemcstNPeqwv8xU radQ+FsTepoBjPtwLBTldgQLkCITM6swMpu/GwOaOxYKRqO0ZNuR+mO1JNn8RwWgi5R3 krfCvWroxbkeNOfZbKPDbeQla9KkJWgRAApQ1rl68H6PmYR/ebOMF+kLyz1PfhKYVtOK QqGqkYdGAKW6LKgQ46hD+GfBbsB7tRiXeqKtEa81XTouP26KKS1HzgVfqqi8IWHV+gsF Rjki7h//xIV9yuIIGxpDa+cTDYI95/VOciOgJI7XxL1DQSe3f5i4nmkPjkSxPwfWR+ps wlwQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=kARdzZ7pCXfcfJdNmi3V5BzYScOWa7HFMQkDjpazwic=; b=bsCIUCgTBaB6DfPYaOWa22o5CrHdo+aaCrDY61sevQaZqBkiEl0By1GBbR3w8QMaQW UwzsZhq3vDEbRI1/k30q2VPGRlaA6//SaPQtUt6f+wRUImIwMQbeUtxV9zUbzg+0+8df KvQ+lLpdF78HJCkH4eFzubqUL5mKLHtMBIetjogdPYJOAJM424l4DLohMJUTkW48dpUT jTpIPFiPBxsjaeU6pJKKe1ZmECRt6mx/x+ijdarxLUCSBEP88haD1UxxmLlsBIxVIBkt RsO0TvEYyIfG2jufu8UxZ4E1XJros7u/olE0k38TGoMaBqiB1PS8apK6fpCY1yvUsgFY kwWg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Zek0SPJj; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id gh14si2659782ejb.650.2020.05.20.19.54.49; Wed, 20 May 2020 19:55:13 -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=@kernel.org header.s=default header.b=Zek0SPJj; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727949AbgEUCvG (ORCPT + 99 others); Wed, 20 May 2020 22:51:06 -0400 Received: from mail.kernel.org ([198.145.29.99]:57198 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726979AbgEUCvE (ORCPT ); Wed, 20 May 2020 22:51:04 -0400 Received: from localhost.localdomain (c-73-231-172-41.hsd1.ca.comcast.net [73.231.172.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 0FD6420756; Thu, 21 May 2020 02:51:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1590029463; bh=pgJQa1w4GgFyUgPZ73SymaRcnYjxRBW/AIT2HJe0HLc=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=Zek0SPJjepnZk3PsEnSKqdkox4ZCbwicJqdnqrTtKclqcasDKhsovb68KfaFRaBRI 02Svn1GgX1piNuLo5ArMVEPB+A+GMPkyUJDrdGlGDpi5gxTHghZ15jleLPB+J+WJX3 zwCkeYtP8fyNgWa20Yxz4A1G8niA6f1MSFD1m3QI= Date: Wed, 20 May 2020 19:51:02 -0700 From: Andrew Morton To: Huang Ying Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Daniel Jordan , Michal Hocko , Minchan Kim , Tim Chen , Hugh Dickins Subject: Re: [PATCH -V2] swap: Reduce lock contention on swap cache from swap slots allocation Message-Id: <20200520195102.2343f746e88a2bec5c29ef5b@linux-foundation.org> In-Reply-To: <20200520031502.175659-1-ying.huang@intel.com> References: <20200520031502.175659-1-ying.huang@intel.com> X-Mailer: Sylpheed 3.5.1 (GTK+ 2.24.31; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 20 May 2020 11:15:02 +0800 Huang Ying wrote: > In some swap scalability test, it is found that there are heavy lock > contention on swap cache even if we have split one swap cache radix > tree per swap device to one swap cache radix tree every 64 MB trunk in > commit 4b3ef9daa4fc ("mm/swap: split swap cache into 64MB trunks"). > > The reason is as follow. After the swap device becomes fragmented so > that there's no free swap cluster, the swap device will be scanned > linearly to find the free swap slots. swap_info_struct->cluster_next > is the next scanning base that is shared by all CPUs. So nearby free > swap slots will be allocated for different CPUs. The probability for > multiple CPUs to operate on the same 64 MB trunk is high. This causes > the lock contention on the swap cache. > > To solve the issue, in this patch, for SSD swap device, a percpu > version next scanning base (cluster_next_cpu) is added. Every CPU > will use its own per-cpu next scanning base. And after finishing > scanning a 64MB trunk, the per-cpu scanning base will be changed to > the beginning of another randomly selected 64MB trunk. In this way, > the probability for multiple CPUs to operate on the same 64 MB trunk > is reduced greatly. Thus the lock contention is reduced too. For > HDD, because sequential access is more important for IO performance, > the original shared next scanning base is used. > > To test the patch, we have run 16-process pmbench memory benchmark on > a 2-socket server machine with 48 cores. One ram disk is configured What does "ram disk" mean here? Which drivers(s) are in use and backed by what sort of memory? > as the swap device per socket. The pmbench working-set size is much > larger than the available memory so that swapping is triggered. The > memory read/write ratio is 80/20 and the accessing pattern is random. > In the original implementation, the lock contention on the swap cache > is heavy. The perf profiling data of the lock contention code path is > as following, > > _raw_spin_lock_irq.add_to_swap_cache.add_to_swap.shrink_page_list: 7.91 > _raw_spin_lock_irqsave.__remove_mapping.shrink_page_list: 7.11 > _raw_spin_lock.swapcache_free_entries.free_swap_slot.__swap_entry_free: 2.51 > _raw_spin_lock_irqsave.swap_cgroup_record.mem_cgroup_uncharge_swap: 1.66 > _raw_spin_lock_irq.shrink_inactive_list.shrink_lruvec.shrink_node: 1.29 > _raw_spin_lock.free_pcppages_bulk.drain_pages_zone.drain_pages: 1.03 > _raw_spin_lock_irq.shrink_active_list.shrink_lruvec.shrink_node: 0.93 > > After applying this patch, it becomes, > > _raw_spin_lock.swapcache_free_entries.free_swap_slot.__swap_entry_free: 3.58 > _raw_spin_lock_irq.shrink_inactive_list.shrink_lruvec.shrink_node: 2.3 > _raw_spin_lock_irqsave.swap_cgroup_record.mem_cgroup_uncharge_swap: 2.26 > _raw_spin_lock_irq.shrink_active_list.shrink_lruvec.shrink_node: 1.8 > _raw_spin_lock.free_pcppages_bulk.drain_pages_zone.drain_pages: 1.19 > > The lock contention on the swap cache is almost eliminated. > > And the pmbench score increases 18.5%. The swapin throughput > increases 18.7% from 2.96 GB/s to 3.51 GB/s. While the swapout > throughput increases 18.5% from 2.99 GB/s to 3.54 GB/s. If this was backed by plain old RAM, can we assume that the performance improvement on SSD swap is still good? Does the ram disk actually set SWP_SOLIDSTATE?