linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Avery Pennarun <apenwarr@gmail.com>
To: David Miller <davem@davemloft.net>
Cc: akpm@linux-foundation.org, josh@joshtriplett.org,
	paulmck@linux.vnet.ibm.com, mingo@elte.hu,
	a.p.zijlstra@chello.nl, fdinitto@redhat.com, hannes@cmpxchg.org,
	olaf@aepfle.de, paul.gortmaker@windriver.com, tj@kernel.org,
	hpa@linux.intel.com, yinghai@kernel.org,
	linux-kernel@vger.kernel.org, linux-mm@kvack.org
Subject: Re: [PATCH 0/5] Persist printk buffer across reboots.
Date: Tue, 13 Mar 2012 04:10:42 -0400	[thread overview]
Message-ID: <CAHqTa-2c7pOTicWO8stNJfVfep4gSPHwKdr3kv_Jk-oi=dU5bw@mail.gmail.com> (raw)
In-Reply-To: <20120313.001842.1454669292182923878.davem@davemloft.net>

On Tue, Mar 13, 2012 at 3:18 AM, David Miller <davem@davemloft.net> wrote:
> I'm only saying that you should design your stuff such that an
> architecture with such features could easily hook into it using this
> kind facility.

How about this?


diff --git a/include/linux/memblock.h b/include/linux/memblock.h
index a6bb102..7335cf7 100644
--- a/include/linux/memblock.h
+++ b/include/linux/memblock.h
@@ -59,6 +59,8 @@ int memblock_add(phys_addr_t base, phys_addr_t size);
 int memblock_remove(phys_addr_t base, phys_addr_t size);
 int memblock_free(phys_addr_t base, phys_addr_t size);
 int memblock_reserve(phys_addr_t base, phys_addr_t size);
+phys_addr_t memblock_reserve_by_name(const char *name,
+	phys_addr_t size, phys_addr_t align);

 #ifdef CONFIG_HAVE_MEMBLOCK_NODE_MAP
 void __next_mem_pfn_range(int *idx, int nid, unsigned long *out_start_pfn,
@@ -246,6 +248,11 @@ static inline phys_addr_t
memblock_alloc(phys_addr_t size, phys_addr_t align)
 	return 0;
 }

+phys_addr_t memblock_reserve_by_name(const char *name,
+	phys_addr_t size, phys_addr_t align)
+{
+	return 0;
+}
 #endif /* CONFIG_HAVE_MEMBLOCK */

 #endif /* __KERNEL__ */
diff --git a/mm/memblock.c b/mm/memblock.c
index 99f2855..2ab4559 100644
--- a/mm/memblock.c
+++ b/mm/memblock.c
@@ -519,6 +519,38 @@ int __init_memblock memblock_reserve(phys_addr_t
base, phys_addr_t size)
 	return memblock_add_region(_rgn, base, size, MAX_NUMNODES);
 }

+#define RESERVE_SEARCH_END 0xfe000000
+#define RESERVE_SEARCH_JUMP (16*1024*1024)
+
+/**
+ * Find a well-defined location for the given memory area and reserve it.
+ * The generic version just scans through memory looking for an available
+ * area, and ignores the name.  An arch-specific version could request a
+ * named area from the bootloader (eg.  prom_retain()) in the hopes of
+ * getting a region guaranteed not to be messed up by the bootloader.
+ */
+phys_addr_t __init_memblock memblock_reserve_by_name(const char *name,
+	phys_addr_t size, phys_addr_t align)
+{
+	unsigned long where;
+
+	for (where = RESERVE_SEARCH_END - align;
+			where >= RESERVE_SEARCH_JUMP;
+			where -= RESERVE_SEARCH_JUMP) {
+		where &= ~(roundup_pow_of_two(align) - 1);
+		if (memblock_find_in_range(where, where + size,
+					size, align) != 0) {
+			memblock_reserve(where, size);
+			printk(KERN_INFO "memblock(%s): "
+				"reserved %lu @ 0x%08lx\n",
+				name, (unsigned long)size,
+				(unsigned long)where);
+			return where;
+		}
+	}
+	return 0;
+}
+
 /**
  * __next_free_mem_range - next function for for_each_free_mem_range()
  * @idx: pointer to u64 loop variable
-- 
1.7.7.3

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

  reply	other threads:[~2012-03-13  8:11 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-03-13  5:36 Avery Pennarun
2012-03-13  5:36 ` [PATCH 1/5] mm: bootmem: BUG() if you try to allocate bootmem too late Avery Pennarun
2012-03-13  5:36 ` [PATCH 2/5] mm: bootmem: it's okay to reserve_bootmem an invalid address Avery Pennarun
2012-03-13  5:36 ` [PATCH 3/5] mm: nobootmem: implement reserve_bootmem() in terms of memblock Avery Pennarun
2012-03-13  5:36 ` [PATCH 4/5] printk: use alloc_bootmem() instead of memblock_alloc() Avery Pennarun
2012-03-13  6:13   ` Yinghai Lu
2012-03-13  6:40     ` Avery Pennarun
2012-03-13  8:26       ` Ingo Molnar
2012-03-13 21:50       ` Yinghai Lu
2012-03-14  2:23         ` Avery Pennarun
2012-03-13  5:36 ` [PATCH 5/5] printk: CONFIG_PRINTK_PERSIST: persist printk buffer across reboots Avery Pennarun
2012-03-13  5:53 ` [PATCH 0/5] Persist " David Miller
2012-03-13  6:00   ` Avery Pennarun
2012-03-13  6:50     ` David Miller
2012-03-13  7:14       ` Avery Pennarun
2012-03-13  7:18         ` David Miller
2012-03-13  8:10           ` Avery Pennarun [this message]
2012-03-13  8:16             ` David Miller
2012-03-13 13:50   ` Peter Zijlstra
2012-03-14  1:57     ` Daniel Walker
2012-03-13  8:32 ` Stephen Boyd
2012-03-13 17:08 ` Daniel Walker
2012-03-13 22:10   ` Andrew Morton
2012-03-14  2:19     ` Daniel Walker
2012-03-15 22:10       ` Seiji Aguchi
2012-03-14  2:21     ` Avery Pennarun

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAHqTa-2c7pOTicWO8stNJfVfep4gSPHwKdr3kv_Jk-oi=dU5bw@mail.gmail.com' \
    --to=apenwarr@gmail.com \
    --cc=a.p.zijlstra@chello.nl \
    --cc=akpm@linux-foundation.org \
    --cc=davem@davemloft.net \
    --cc=fdinitto@redhat.com \
    --cc=hannes@cmpxchg.org \
    --cc=hpa@linux.intel.com \
    --cc=josh@joshtriplett.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mingo@elte.hu \
    --cc=olaf@aepfle.de \
    --cc=paul.gortmaker@windriver.com \
    --cc=paulmck@linux.vnet.ibm.com \
    --cc=tj@kernel.org \
    --cc=yinghai@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox