Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp2332404ybt; Fri, 3 Jul 2020 06:42:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzcD2yo/e14z/DLuOcrhKtmi1CA8FLkQuJcIBLh/cqUdYyasG+hbrS+zRL8kUDR5+l0iwy4 X-Received: by 2002:a05:6402:741:: with SMTP id p1mr39975791edy.222.1593783761084; Fri, 03 Jul 2020 06:42:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593783761; cv=none; d=google.com; s=arc-20160816; b=kcxL1V6Uikk/s9dcrACekdi8ZSjPs/jRphoNRshLs9H2r23ks1tnU8Gg8OFeC3Lv+v mYo0VgG8z8PkJMAW5T6SNXYWnQaDMFSh5DOdttVUrSkgRFzU4OIugxd4WgfamigTdj+b zcFmfYnb3Ay2X96+jmx4lVxDUm+JX8wER+c2+9IqJKKaFGjDDfKMXlpvWE7tw5EzrJqo kBn0EtBqaezIddofgQNxjmq1kf3NV1EgWNn5Gfunixz9Gb2bCqFrywqEYh8R35iZNMze W2MwEQrUSHuwS63cuJ3pYwLtHyviOeTC97Uzd7oEzlK4fxg3Ny8NUC0lzIWXVwnWgSfs dEcA== 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:date:subject:cc:to:from :dkim-signature; bh=3i/7HG3E2Y5FgAWZXKhOsCstaQ5rwPr72fTo1BaNePY=; b=AjewWCupPpVJDiyzpc+rSppaucKOfFoKT4/bfkdt2D8yCHRa29ZClS3CVoj+OxDXPR lXeo+G5Y6KYHGwnDf7+kmCXUenTxRHtHj6Q3RlaAaefPAoPlmrpTLdUSPG7TO/iJAigl N8HCLxAWItLvYSmEauWIqnIQnvyRBizpkKirmt85dT4aaD1ZmUnTxVrbiKt0dn0THRQP h84DqlShuEOCAcuVPeLtXVUdnSY/E8vrHrSbbyUxlFgrO6yV564SGRo3dIehGvMUEeUE l8NKeMhhyoWUdGnqOq0wcjl5unfCH5FoQ/RT4NU5rvFPl65vujG9px5t+tr8C3Tvgoos QdPQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=cKMguHne; 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 f20si8021939edc.220.2020.07.03.06.42.17; Fri, 03 Jul 2020 06:42:41 -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=cKMguHne; 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 S1726741AbgGCNjv (ORCPT + 99 others); Fri, 3 Jul 2020 09:39:51 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:26321 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726147AbgGCNjt (ORCPT ); Fri, 3 Jul 2020 09:39:49 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593783587; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=3i/7HG3E2Y5FgAWZXKhOsCstaQ5rwPr72fTo1BaNePY=; b=cKMguHnecJQzkcQzlXMnm53I0BAcmDsYvOcSyS4fmhZ6X7Uv3Oz2g81IIEgVDgRQiD3MWm j/M5HHSaYtw4TR4RTJGwfYdqJgyHvSdpQEcCWEaDj9JrlgSR7Rxbg0GqVEOKdAc8ruO/Uq rDR8mFc8e5d1skPaVHBqz0FNaH/iF+M= 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-478-FLh4HO9OO-SgYyk7VG0xvQ-1; Fri, 03 Jul 2020 09:39:44 -0400 X-MC-Unique: FLh4HO9OO-SgYyk7VG0xvQ-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A04642268; Fri, 3 Jul 2020 13:39:42 +0000 (UTC) Received: from t480s.redhat.com (ovpn-114-0.ams2.redhat.com [10.36.114.0]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3FBA97AC75; Fri, 3 Jul 2020 13:39:38 +0000 (UTC) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-s390@vger.kernel.org, linux-mm@kvack.org, David Hildenbrand , Heiko Carstens , Vasily Gorbik , Christian Borntraeger , Gerald Schaefer Subject: [PATCH v1 9/9] s390/vmemmap: avoid memset(PAGE_UNUSED) when adding consecutive sections Date: Fri, 3 Jul 2020 15:39:17 +0200 Message-Id: <20200703133917.39045-10-david@redhat.com> In-Reply-To: <20200703133917.39045-1-david@redhat.com> References: <20200703133917.39045-1-david@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Let's avoid memset(PAGE_UNUSED) when adding consecutive sections, whereby the vmemmap of a single section does not span full PMDs. Cc: Heiko Carstens Cc: Vasily Gorbik Cc: Christian Borntraeger Cc: Gerald Schaefer Signed-off-by: David Hildenbrand --- arch/s390/mm/vmem.c | 45 ++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 42 insertions(+), 3 deletions(-) diff --git a/arch/s390/mm/vmem.c b/arch/s390/mm/vmem.c index a981ff5d47223..9db15fc864fc8 100644 --- a/arch/s390/mm/vmem.c +++ b/arch/s390/mm/vmem.c @@ -74,7 +74,22 @@ static void vmem_pte_free(unsigned long *table) #define PAGE_UNUSED 0xFD -static void vmemmap_use_sub_pmd(unsigned long start, unsigned long end) +/* + * The unused vmemmap range, which was not yet memset(PAGE_UNUSED) ranges + * from unused_pmd_start to next PMD_SIZE boundary. + */ +unsigned long unused_pmd_start; + +static void vmemmap_flush_unused_pmd(void) +{ + if (!unused_pmd_start) + return; + memset(__va(unused_pmd_start), PAGE_UNUSED, + ALIGN(unused_pmd_start, PMD_SIZE) - unused_pmd_start); + unused_pmd_start = 0; +} + +static void __vmemmap_use_sub_pmd(unsigned long start, unsigned long end) { /* * As we expect to add in the same granularity as we remove, it's @@ -85,18 +100,41 @@ static void vmemmap_use_sub_pmd(unsigned long start, unsigned long end) memset(__va(start), 0, sizeof(struct page)); } +static void vmemmap_use_sub_pmd(unsigned long start, unsigned long end) +{ + /* + * We only optimize if the new used range directly follows the + * previously unused range (esp., when populating consecutive sections). + */ + if (unused_pmd_start == start) { + unused_pmd_start = end; + if (likely(IS_ALIGNED(unused_pmd_start, PMD_SIZE))) + unused_pmd_start = 0; + return; + } + vmemmap_flush_unused_pmd(); + __vmemmap_use_sub_pmd(start, end); +} + static void vmemmap_use_new_sub_pmd(unsigned long start, unsigned long end) { void *page = __va(ALIGN_DOWN(start, PMD_SIZE)); + vmemmap_flush_unused_pmd(); + /* Could be our memmap page is filled with PAGE_UNUSED already ... */ - vmemmap_use_sub_pmd(start, end); + __vmemmap_use_sub_pmd(start, end); /* Mark the unused parts of the new memmap page PAGE_UNUSED. */ if (!IS_ALIGNED(start, PMD_SIZE)) memset(page, PAGE_UNUSED, start - __pa(page)); + /* + * We want to avoid memset(PAGE_UNUSED) when populating the vmemmap of + * consecutive sections. Remember for the last added PMD the last + * unused range in the populated PMD. + */ if (!IS_ALIGNED(end, PMD_SIZE)) - memset(__va(end), PAGE_UNUSED, __pa(page) + PMD_SIZE - end); + unused_pmd_start = end; } /* Returns true if the PMD is completely unused and can be freed. */ @@ -104,6 +142,7 @@ static bool vmemmap_unuse_sub_pmd(unsigned long start, unsigned long end) { void *page = __va(ALIGN_DOWN(start, PMD_SIZE)); + vmemmap_flush_unused_pmd(); memset(__va(start), PAGE_UNUSED, end - start); return !memchr_inv(page, PAGE_UNUSED, PMD_SIZE); } -- 2.26.2