char/mem: Honor O_SYNC over intelligent setting of uncached access
RFC 1/1 char/mem: Honor O_SYNC over intelligent setting of uncached access
The original code will automatially set the page non-cacheable if the mmap'ped address is not in kernel managed low memory.
We already have O_SYNC flag to pass the cacheability settings. Therefore we should
honor the case that O_SYNC is delibrately not used. For example, it is useful to the case that not all system memory is managed by Linux, and want to be mmaped cacheable.
Not sure if there is anything out there depending on the previous behavior.
--- drivers/char/mem.c | 8 +++----- 1 files changed, 3 insertions(+), 5 deletions(-)
drivers/char/mem.c +3 -5
@@ -56,12 +56,10 @@ static inline int uncached_access(struct file *file, unsigned long addr) }#else /* -* Accessing memory above the top the kernel knows about or through a file pointer -* that was marked O_SYNC will be done non-cached. +* Accessing memory through a file pointer that was marked O_SYNC will be done +* non-cached. */ -if (file->f_flags &O_SYNC ) -return 1 ; -return addr >=__pa (high_memory); +return (file->f_flags &O_SYNC ) ?1 :0 ;#endif }
Signature · 1 line
1.6.3.1.6.g4bf1f
Li Yang <[email protected]> writes:
D> The original code will automatially set the page non-cacheable if the mmap'ped
Quoted 7 lines
address is not in kernel managed low memory.
We already have
O_SYNCflag to pass the cacheability settings. Therefore we should
honor the case thatO_SYNCis delibrately not used. For example, it is useful to the case that not all system memory is managed by Linux, and want to be mmaped cacheable.Not sure if there is anything out there depending on the previous behavior.
Very likely there is. That change seems rather dangerous.
If you wanted to do something like this you would need a long deprecation period with printks and format warnings. But most likely it's not worth it, what advantage does the change have?
-Andi
Signature · 1 line
[email protected] -- Speaking for myself only.
Quoted 9 lines · Andi Kleen
Li Yang <[email protected]> writes:
D> The original code will automatially set the page non-cacheable if the mmap'ped
Quoted 6 lines
address is not in kernel managed low memory.
We already have
O_SYNCflag to pass the cacheability settings. Therefore we should honor the case thatO_SYNCis delibrately not used. For example, it is useful to the case that not all system memory is managed by Linux, and want to be mmaped cacheable.
Quoted 7 lines
Quoted 1 line
Not sure if there is anything out there depending on the previous behavior.
Very likely there is. That change seems rather dangerous.
If you wanted to do something like this you would need a long deprecation period with printks and format warnings. But most likely it's not worth it, what advantage does the change have?
The general advantage is that user has the true control of the page cacheability through O_SYNC file open() flag. For the previous way, kernel might map memory as non-cacheable when it's not necessary. One most common use case is that, user could limit the memory managed by kernel and mmap the memory manually. But he can't make that VMA cacheable. The user should have a better idea than kernel if a certain memory space is I/O or not when using mmap().
- Leo